Most components do not replicate. Most gameplay logic is done in the Actor class and components usually just represent smaller pieces that make up the Actor.
Components replicate as part of their owning Actor.
对Component的replication来说,主要是两类Components:
- Static Components
- Dynamic Components
静态Components是随Actor的Spawn一起产生的,即在Actor的构造函数里创建的。当Components的Owning Actor在client或server上创建时,这些components就一起被创建出来了,不管这些Components被标记为replicated与否。
这个意思其实就是:标记为Replicated的Actor在Server端创建出来时,其会同步这个Spawn动作到所有client端,导致client端也会创建出一个Actor,而Static Components属于Actor的创建的一部分,自然会在Actor的创建过程中被创建出来。
说静态Components的同步,其实指的是其属性或事件等的同步,其自身都是随各自的Owning Actor的构造过程被创建出来的。而不是说:Actor在server端创建一个Actor的空壳子,然后通知clients也创建一份Actor的空壳子,再server端创建一个静态component,通知clients也创建一个静态components!不是这样的。
动态Components是运行时在server端创建的,其创建和销毁都要下发到clients,就像Replicated Actor一样。
- Unlike static components, dynamic components need to replicate to exist on all clients.
- Alternatively, clients can spawn their own local, non-replicating components. This is actually fine in many cases.
这段话的意思是:所谓的dynamic components可以像Actor一样进行replication相关设定处理。但也可以不这么做,不用将components本身设置为replication的一部分,只需要通过Actor的replication机制,让所有clients都有各自本地的相应components即可,同样也是经由OwningActor的replication机制,让这些components达成一致状态。 但是,如果想要dynamic components的属性和server端触发的事件能自动同步的话,则必须将dynamic components标记为replication。