Search Unity

is pausing a ComponentSystem possible -- or something with similar effect?

Discussion in 'Entity Component System' started by uani, Feb 25, 2019.

  1. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Hello,

    I'm looking into transforming an approach using
    Job
    s for a
    GameObject
    driven design of mine into ECS + Job s.

    On this occasion I would like to be able to pause a
    ComponentSystem
    :

    Imagine many big cubes each containing many small cubes: every big cube has a
    World
    giving an
    EntityManager
    and its contained small cubes have
    Component
    s. When a big cube is not in view of the players camera I would like to pause the
    ComponentSystem
    acting on the
    Component
    s of this big cubes small cubes. The reason being to reduce CPU workload where possible.

    Is this possible or is something similar possible? -- how ? :)

    Apologies for possibly missing ' and the plural s syntax.

    Resources I've studied:
    https://unity3d.com/learn/tutorials/topics/scripting/implementing-ecs?playlist=17117 timecode 5:48
    https://github.com/Unity-Technologi.../blob/master/Documentation~/entity_manager.md
    https://github.com/Unity-Technologi...emSamples/blob/master/Documentation~/world.md
    https://github.com/Unity-Technologi...master/Documentation~/job_component_system.md
    https://github.com/Unity-Technologi.../master/Documentation~/system_update_order.md
    https://github.com/Unity-Technologi...lob/master/Documentation~/component_system.md
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Depending of the approach:

    You can either have group system, which require entities with certain tags. In such case, you have empty IComponentData tag in entity, without data. Then you just add / remove, to activate / deactivate entity, form being processed by such system.

    Or, having bit set, when iterating through entities in a system and enable / disable it, accordingly, to process data, or not. Simply using if loop for that purpose.

    First approach is specifically good, when you have tons of entities, but you don't need set tags every frame. Also, if you have many systems, which may be affected by similar entities groups.
    Second approach may be more convenient, if you your state changes every frame on many entities.
     
    uani likes this.
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Enabled = false
     
    uani and Sibz9000 like this.
  4. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Hi, thank you! I'll try these approaches. I thought of adding/removing a component too but guessed it likely isn't a "good" approach from a performance perspective.
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Adding / Removing empty IComponentData as tag, is apparently treated differently, than components with data.
    Haven't tested, but I suspect, it is faster than creating entity from archetype.

    Setting bit is the fastest to set, but you still have entity iterated through system, even don't need them.
     
  6. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Hi, thank you again! In your first answer you mention "group system" and you mention "tag". I thought this to be Unity-independent terms but now I found https://github.com/Unity-Technologi...blob/master/Documentation~/component_group.md . Did you mean this? So by tag you also mean to use
    tag
    s (like
    layer
    s)?
    ComponentGroup
    appears like my "logic culling" or "logic LOD" was thought of when designing these. So I would use a
    ISharedComponentData
    on each
    Entity
    (small cube) and then would use something like
    m_Group.SetFilter(new SharedGrouping { Group = 1 })
    ,
    m_Group
    being a
    ComponentGroup
    and
    Group
    being the data of that. And I would also use
    [URL='https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html']FindGameObjectsWithTag[/URL]
    ?
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Yep, ComponentGroup
    GetComponentGroup
    For example
    Code (CSharp):
    1. ComponentGroup group ;
    2. group = GetComponentGroup
    3.             (        
    4.                 // typeof ( Disabled ), // Example of existing Disabled component data.
    5.                 typeof ( TagComponentData ),
    6.                 typeof ( SomeOtherComponentData )
    7.             ) ;
    But in this case, I wouldn't be using !SharedComponentData, nor filter.
     
  8. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Hi, thank you!

    I'm now working on it and have created an "isInViewSystem" which calculates the distance of each big cube having a DistanceComponent to the "Main Camera" (note: I'm describing this in the terms of the original post, they are not big cubes actually). Now I want to create a System X which works with each small cube having a SharedComponentData which sets this SharedComponentsData value to 1 or 0 depending on the given distance in the main cube. For this I wanted the big cube be a world ("new World(name)") and assign the System X to this World.

    Do you happen to know how I can assign
    ComponentSystem
    s to a world? Note: every big cube being like another they will each need to have the "same"
    ComponentSystem
    in their world, but that
    ComponentSystem
    only operating on the
    World
    s entities.

    How can I accomplish this (other than figuring out Packages/com.unity.entities/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs) ?
     
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    I don't use ComponentSystem. I use IComponentSystem.
    Each world can have own set of entities. Therefore, they can work independently.