Couldn’t find anything around this for 1.0. What’s the best way to enable/disable systems programmatically?
I think I figured it out:
World.Systems[0].enabled = false;
Just need to iterate over the systems to find the one you want.
You likely want something like this:
World.GetExistingSystemManaged().Enabled = false;
Nice. That’s actually better. How about unmanaged systems (systems that inherit from ISystem)? Can’t find a way to enable/disable them.
Thats the way id do it:
var systemHandle = World.GetExistingSystem<MyUnmanagedSys>();
var unmanagedSystem = World.Unmanaged.GetUnsafeSystemRef<MyUnmanagedSys>(systemHandle);
unmanagedSystem.Enabled = false;
Maybe there is a better way idk.
I don’t know your use case but you should also consider
RequireForUpdate(entityQuery) as an option. Thats usually what i go with.
That’s perfect. Thanks. I have used RequireForUpdate before. My use case is more so for some custom debugging purposes. Not anything to be used for production so doesn’t need to be fancy.
Hmm, just tried it and “Enabled” does not exist on “ISystem”.
Example of unmanaged systems in a context I actually use: Latios-Framework/Core/Framework/CoreBootstrap.cs at v0.6.4 · Dreaming381/Latios-Framework · GitHub
I also just found that you can use “GetExistingSystemState”:
World.Unmanaged.GetExistingSystemState<MyUnmanagedSys>().Enabled = false;
Is this for 1.0? I use Entities 1.0.0-pre 15. this API is not valid for me.
It is. I am using 1.0.0-pre.15 as well. What error are you seeing? Note that this API is for unmanaged systems (systems that inherit from ISystem). If your system is managed (inherits from SystemBase) then use this API:
world.GetExistingSystemManaged<MyManagedSystem>().Enabled = enabled
I could use it as;
var systemHandle = World.DefaultGameObjectInjectionWorld.GetExistingSystem<ChildMoveSystem>();
How can I get unmanaged system and access it’s custom fields? World.DefaultGameObjectInjectionWorld.GetExistingSystem() returns SystemHandle. I want to access my system ChildMoveSystem.
If your ChildMoveSystem is unmanaged system
var handle = World.DefaultGameObjectInjectionWorld.GetExistingSystem<T>();
var systemReference = World.DefaultGameObjectInjectionWorld.Unmanaged.GetUnsafeSystemRef<T>(handle);
If your system is managed
var systemReference = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<T>();