Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Enabling and Disabling Systems for Unity ECS

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

  1. Ootgard

    Ootgard

    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 Ootgard 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:
    113
    can you disable a system precompiled? So it is not even in the game?
     
  8. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    67
    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:
    113
    ty this is what I was looking for
     
    bugfinders likes this.
unityunity