Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question on deterministic behaviour

Discussion in 'Entity Component System' started by Brammel, Jul 18, 2020.

  1. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Hi, i'm working on a game using the lockstep protocol, and therefore require determinism from simulations.

    There are 3 examples i wonder about:

    1) Do "readonly (only "in", so no "ref" components) matter?
    As i understand, in components do not modify the state, they just read. So if i have 2 worlds, that differ only by read only systems, are they still deterministic?

    2) Do "Tag" components matter if no system uses them?
    given 2 simulations, where i simply add a tag component to all entities in 1 simulation, but not in the other, is the output of the simulation still equal? (the tags are not referenced anywhere, and so do not alter the execution of any system).

    3) Can my current setup be deterministic?
    I currently have 1 world with the 3 different systemupdategroups. However, i manually control the "simulationgroup" (disabled it and manually step it in fixedupdate). The presentation and initializationgroup however are still updated in update (like they do by default).
    In this setup, will the state still be identical if i guaratee that 2 worlds have made equal amounts of steps in the "simulationgroup"?

    Would be incredibly helpfull if someone could answer these questions.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    1) I think they will matter as your jobs could be scheduled in a different order due to dependencies unless you use simple dependency scheduling

    2) not sure, good question. I think you'd need to check chunk utilisation was exactly the same

    3) pretty sure that's fine.
     
  3. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Thanks for the answers, a few followup questions:

    1) I think they will matter as your jobs could be scheduled in a different order due to dependencies unless you use simple dependency scheduling

    - As far as i understand, systems are updated in the same order as they appear in the updategroup. Say i have system A first (updatebefore(B)) and system B second (updateafter(A)), then system B will wait for system A if there is a component dependency. It sounds logical to me that any readonly system inbetween A and B would simply force B to wait longer, but not execute differently.

    2) not sure, good question. I think you'd need to check chunk utilisation was exactly the same
    - Lets say these empty components contain data, then less would fit in a chunk. Is there any mechanism for me to ensure chunk utilisation is equal?

    3) pretty sure that's fine.
    - Isnt it the case that the rendersystems add several components to rendermesh to display it? Wouldnt that interfere with question #2, where the components added and removed happen at different frequencies? (for instance, the simulationworld could step multiple times before a single rendering update in some extreme scenarios).
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    System order != job execution order (except in simple dependency)
    This is the whole point of read/write and why it's important to correctly set things as read where possible.

    upload_2020-7-19_8-26-14.png
    Not that I'm aware of.

    Well yeah, if you were making changes to the entities in init/presentation it would no longer be deterministic. I'd separate the rendering from the logic entities in this case.
     
  5. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Well yeah, if you were making changes to the entities in init/presentation it would no longer be deterministic. I'd separate the rendering from the logic entities in this case.

    - I dont, but afaik this is the default behaviour of the unity systems.

    Are there any examples of how to seperate those 2 worlds (render, simulation)?.
    I found some examples of client-server worlds, but since mine can hold direct references to one another i figured there are faster/better ways of syncing worlds.