Search Unity

Enabling and Disabling Systems for Unity ECS

Discussion in 'Data Oriented Technology Stack' started by Jotunheimr, May 23, 2018.

  1. Jotunheimr

    Jotunheimr

    Joined:
    Dec 4, 2012
    Posts:
    1
    Is there a way to enable and disable individual systems programmatically for Unity ECS?
     
  2. Prastiwar

    Prastiwar

    Joined:
    Jul 29, 2017
    Posts:
    125
    Yes, systems, so ScriptBehaviourManagers have property "Enabled"

    EDIT: In newer version Enabled property is from ComponentSystemBase
     
    Last edited: Jun 2, 2018
    starikcetin, 5argon and Jotunheimr like this.
  3. hellowill89

    hellowill89

    Joined:
    Jan 8, 2013
    Posts:
    42
    Do you have a more complete example of how to do this?
     
  4. Prastiwar

    Prastiwar

    Joined:
    Jul 29, 2017
    Posts:
    125
    Code (CSharp):
    1. public class ComponentSys : ComponentSystem
    2. {
    3.     [Inject] private SomeSystem someSystem;
    4.  
    5.     protected override void OnUpdate()
    6.     {
    7.         if (disableSomeSystem)
    8.             someSystem.Enabled = false;
    9.     }
    10. }
    or

    Code (CSharp):
    1. public class SomeClass : MonoBehaviour
    2. {
    3.     private void SomeMethod()
    4.     {
    5.         World.Active.GetExistingManager<SomeSystem>().Enabled = false;
    6.     }
    7. }
     
    stylophone and Bas-Smit like this.
  5. hellowill89

    hellowill89

    Joined:
    Jan 8, 2013
    Posts:
    42
    I see, awesome. I didn't know the system would be the type of the `GetExistingManager` call.
     
  6. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    In case anyone needs this, GetExistingManager is now renamed to GetExistingSystem
     
  7. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    99
    can you disable a system precompiled? So it is not even in the game?
     
  8. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    58
    Hmm - I think at that point you may not even want to create the System automatically using the [DisableAutoCreation] attribute on the system.

    If you need later you can always create the system into the world.
     
  9. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    99
    ty this is what I was looking for
     
unityunity