Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Optimizing for Structural Changes

Discussion in 'Entity Component System' started by PublicEnumE, May 30, 2020.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    In a project, there are 5 systems, which add or remove 5 different types of components:

    - SystemA adds ComponentA to an entity.

    - SystemB removes ComponentB from the same entity.

    ...and so on. Each of these system uses Bursted Jobs, and schedules the components to be added or removed using EntityCommandBuffers from an ECBSystem.

    when the ECB is eventually played back, it will perform the add and remove commands in sequence. Meaning: the one entity from above could have its data copied and then removed from five different chunks in rapid succession.

    I wish there was some way to simplify this, so that only a single archetype change needs to occur: All I’m really concerned with is where they entity ends up: I just need to it to exist in a chunk with the right component types, when the ECB playback is complete.

    Is there any way to do that now (while still using multiple systems, jobs, and Burst)? I imagine is could have a great impact on my ECB playback time, and would scale better than doing all those chunk moves sequentially.

    Thank you for any advice!
     
    Last edited: May 30, 2020
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    One optimization that is comming is the ability to Enable/Disable components.
    This would allow the entity to not change archetype while still being filtered propoerly based on only the Enabled components.

    While this is not yet implemented, you can add an Enabled bool to you component data and filter that manually in your jobs.
     
    PublicEnumE likes this.
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Wow, I had not heard about this! Thank you for the tip. Do you know a source I could look at to learn more?

    Without knowing more, I imagine an entity with a disabled component would still have lower chunk utilization than it would without the component. Though I’m sure there would be cases when the trade off ended up being worth it.

    Would love to know more, thank you.
     
    Last edited: May 31, 2020
  4. EduardoLauer

    EduardoLauer

    Joined:
    Jun 10, 2013
    Posts:
    8
    There is nothing out yet, it was mentioned here by Joachim Ante.