Search Unity

Question Right way to create a sync point in ECS ?

Discussion in 'Entity Component System' started by hoangcuong2k1a, Feb 5, 2023.

  1. hoangcuong2k1a

    hoangcuong2k1a

    Joined:
    Jan 9, 2023
    Posts:
    14
    A synchronization point (sync point) is a point in the program execution that will wait for the completion of all jobs that have been scheduled so far. Sync points hence limit your ability to use all worker threads available in the job system for a period of time. You should generally aim to avoid sync points.
    https://docs.unity3d.com/Packages/com.unity.entities@0.4/manual/sync_points.html

    So if i want to make a sync point, that mean i need create a lifetime for my game ?
    Example:
    I have 3 methods BeforeUpdate - Update - LateUpdate.
    In this case, is LateUpdate a sync point ?
     
    Last edited: Feb 5, 2023
  2. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    628
    No. Sync points occur naturally (automatically) whenever you call APIs that need sync points. Structural changes in particular directly cause sync points because data needs to be moved around and it’s unsafe to have jobs still be running when data structures are being updated. You generally want to design your game to avoid structural changes (such as adding / removing entities or components, changing shared components). When structural changes are necessary, queue them up in an EntityCommandBuffer obtained from a system that provides them, and they’ll be played back with other ECBs.
    https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/systems-entity-command-buffers.html
     
  3. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    628
    That page is from a version of Entities more than 3 years out of date.
    See a current version below.
    https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/concepts-structural-changes.html
     
  4. hoangcuong2k1a

    hoangcuong2k1a

    Joined:
    Jan 9, 2023
    Posts:
    14
    Wow, thank you so much!
    Can you mention me a blog or some reference on game design without changing the structure?
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    For such design, you want to avoid creation and removal of components and tag at runtime. Specially sometime after entities are created.

    Creation and destruction of entities also require sync points, but that may be unavoidable, in many type of games.

    However, in some cases using component tags can be useful for jobs filtering entities.

    With DOTS 1.0, you can avoid tags creations, while you can enable and disable components at the runtime.
     
    hoangcuong2k1a and Anthiese like this.