What is best-practice for synchronizing entities between multiple worlds

Hi. I have a question about synchronizing components data between multiple worlds.

Example case is that the game has 3 worlds, simulation world, presentation world and UI world.
Clearly, presentation world and UI world need to know information about game character or unit from simulation world.

But it does not need all of data, so it seems that EntitiyManager.CopyEntitiesFrom() is overkill (ex, presentation world absolutely not need physics-related data). It only needs some transform data and other small metadata (like characters status), so another method is using EntityManager.Get/SetComponent() (referenced from other world) manually for each entities. But it may be slow I think.

Is there any best-practice for this case? Any ideas or resource are welcome.

Thanks.

What would be the best for performance ?

  1. copy the full entity and leave the unused data in the presentation world ? That would results in poor chunk usage on the presentation world.
    2 ) rework your entity to split them in 2 entities one for presentation and one for simulation. You would still use the move entity from world, so no loss there and your chunks utilization for the presentation world would be better than keeping unused data. On the flip side your pure simulation system will also have better chunk utilization but of one job ever need both presentation and simulation data simultaneously you will have to use random access one one or the other.

Other than that there may be a way to use unsafe code to copy memory by chunks knowing the origin and destination archetype but that seems risky and hard to maintain to me.(maybe I’m too scared of unsafe code :p)

Question for my curiosity :
Why split presentation and simulation worlds ?
If you are in a network situation (client presentation /server simulation) wouldn’t the client benefit of the physics data for interpolation/prediction?

1 Like

Thanks for reply. The most important reason for using multiple worlds is determinism for lock-step network game. Source is here : https://discussions.unity.com/t/708142/4

I would actually just query the data that is needed by the presentation world positions and rotation etc. You can do this with entity queries.

Obviously you need to manually update the simulation world. So you can control its synchronization.

I would not have a separate UI world.

1 Like