Component Replication归属权
创建一个Component后, 其由哪个Actor负责传输呢? 放到其Owner的ActorChannel里面进行传输.
查看如下代码,
UTestRepFlowSpawnedCmp
的传输由ABasePlayerController
负责.
即其归属于ABasePlayerController
的ActorChannel.
UTestRepFlowSpawnedCmp
对应的FObjectReplicator
存储在ABasePlayerController ActorChannel
的UActorChannel.ReplicationMap
中.
原因: 关键函数NewObject
中经过层层调用,
最终调用了AActor.AddOwnedComponent
,
将该ActorComponent
放入了其UActorComponent.OwnerPrivate
的AActor.ReplicatedComponents
中.
在AActor.ReplicateSubobjects
中,
遍历所有AActor.ReplicatedComponents
进行Replication
.
延伸: 当其Outer不是Actor怎么办呢? 递归寻找其Outer, 直到找到一个为Actor类型的为止.
总结: ActorComponent的网络归属跟Outer有关, 跟谁在使用它无关.