Search Unity

Question Turning systems on and off with singleton tags in ECS 1.0

Discussion in 'Entity Component System' started by Mockarutan, Feb 13, 2023.

  1. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    In my current 0.50 implementation I use tag components to turn different systems on and off. For example, when in singleplayer I do not add the "NetworkedGameplayTag" component and about 10 systems scattered around in different parts of the frame does not run. Or when playing a network replay, the "ReplayTag" is added and all replay systems are turned on. Additionally I have all my singletons (tag or not) on one single entity since I do not want 50 different chunks with one component or tag in each.

    With 1.0 singletons seems to be much more streamlined, rendering my single entity solution unnecessary. But are the tag solution still a good solution for my systems (if it ever was?) or are that some other recommended way?

    Then the more concrete and important part of this problem that I have is: When inside of a job, and the only option to change stuff outside of the current entity is a EntityCommandBuffer, how do I add a singleton tag? EntityManager.CreateSingleton does unique things, and is not present in the EntityCommandBuffer API. So is there a way to do that in a job? Or what happens if I create an entity and attach a component or tag component with the EntityCommandBuffer? That would create a new chunk I presume?

    As I write this I realize that the new IEnableableComponent thing might be good for this? So maybe the right way is to add all the components and then enable and disable them accordingly?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    That still applies in 1.0.

    That would create a new instance of the tag, regardless of if one already exists. If one already exists, then later you will get an assertion about there being more than one singleton.

    You are slamming hard into the limitations with singletons. Like you, I also use a custom entity for storing such tags, and I use a custom callback for each system to choose whether or not to run it. https://github.com/Dreaming381/Lati....4/Documentation~/Core/Blackboard Entities.md
     
  3. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    Wait, so CreateSingleton in EntityManager does not create a special chunk for singletons? That's that point then? Is it just to combine a CreateEntity and AddComponent call?

    Edit; looking though the source it looks like it just a CreateEntity and AddComponent combined...
     
    Last edited: Feb 13, 2023