Search Unity

Cant use CreateManager when the System uses the [DisableAutoCreation] Attribute.

Discussion in 'Entity Component System' started by Opeth001, Mar 18, 2019.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hi guys.
    im trying to create a game and experimenting the ECS (*_*).

    Knowing that all ECS systems dont need to be Created or attached to gameobject to Run, everything it needs is a valid set components existing within entities.

    but in my game i need some systems to run only in specific moments or in specific scenes, i found that using the [DisableAutoCreation] attribute prevents the system from being automatically created at start.
    but when i use World.Active.CreateManager or GetExistingManager<SomeSystem>().Enabled = true; the System still sleeping and i have no idea how to start it. the only solution i found is to add this line this.Enabled = false; within the OnCreateManager() and then Enable it but i think there's better ways of doing it.

    1) is there any other way of doing it ??
    2) can you give more Attributes that can be used with C# Jobs and Systems ? ( or a link for more details )

    Thank you.
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    It’s not about updatebefore/updateafter. My post about new way of manual creating systems in proper way.
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I don't like [DisableAutoCreation] since it removes your system from too many convenience. Rather, it would be the best design if that "specific moment" is triggered by entity matching your component group and cause an update. Then you can just let it create by default and let it sleep until that moment.

    If your specific moment is not tied to any entity but you want to just run once, you can get the manager and use .Update() on demand without it being in the player loop.

    But if you want it to run continuously without any component group at all, but able to turn on-off at will, I would suggest you use something like RequireSingletonForUpdate<GameplayScene> in your OnCreateManager. Then create 1 entity with GameplayScene tag component when you want them to run, destroy when you want to stop. It is cleaner than having to turn on-off and you can make more systems to "subscribe" to this singleton.