I’d like to ask if there’s a way to disable and/or enable systems from, let’s say, a mono behaviour ?
I’m trying to have a “catalog” of systems that I’d like to enable and disable at will instead of them starting automatically. Maybe there’s already a built-in way to do it. If so, could you point me to where to check ?
I tried the code from the following thread but it’s deprecated (The “Enabled = false” section)
Unless I am blind, the Enabled property is not deprecated. I suspect what is actually deprecated for you might be the API you are using to retrieve the system, of which there is likely an alternative you should be using instead that is just a little bit different but not enough to cause you major problems.
I’m actually using Entities 1.0.8 and, I cannot access the “Enabled” property. You’re right: Maybe it’s not deprecated and I used the wrong word but what’s true is that I cannot use this property at all. Is there something I’m doing wrong ? Or, is there another way to enable/disable systems ? (or, if it’s a good idea to do so) ?
Are you trying to access the Enabled property on an ISystem? If so, that’s your problem. You need to resolve the SystemState first, which has the Enabled property.
Sorry. I just realized what is going on. There’s so many variants to the APIs that have changed over the years. I suspect that GetExistingSystem is returning a SystemHandle. From that, you need to pass that handle into World.Unmanaged.ResolveSystemStateRef().
Hey @DreamingImLatios , no problem !! I’ve run into that api variant issue a lot as well.
Yes, GetExistingSystem des return a SystemHandle as you mentioned. However, “World.Unmanaged” doesn’t exist at all in the API. Maybe it’s happening what you mentioned here as well about another API change
You need an instance of the World to access Unmanaged. It is not a static field. In SystemBase and SystemState, those also have a property written exactly identical to the class name, hence the confusion.
Ohh, I see. Perfect. Thanks a lot for your help ! I tried it and indeed, I was able to find the Enabled property. However, it looks like it’s not doing anything to the system. Am I missing something ?
I was able to solve thanks to @DreamingImLatios help in his Discord channel ! His suggestion is to get the SystemHandle from the ResolveSystemStateRef() method as a ref.
Here’s an example of how it can be used from within a MonoBehaviour:
{
// Get the default world
var world = World.DefaultGameObjectInjectionWorld;
// Get the specific ECS system you want to disable
SystemHandle mySystem = world.GetExistingSystem<YOUR_SYSTEM_TYPE>();
ref SystemState state = ref world.Unmanaged.ResolveSystemStateRef(mySystem); // REF USED HERE
state.Enabled = false;
}
public void EnableSystem()
{
// Get the default world
var world = World.DefaultGameObjectInjectionWorld;
// Get the specific ECS system you want to enable
SystemHandle mySystem = world.GetExistingSystem<YOUR_SYSTEM_TYPE>();
ref SystemState state = ref world.Unmanaged.ResolveSystemStateRef(mySystem); // REF USED HERE
state.Enabled = true;
}```
Use code tags. Don’t send screenshots of code, those are pointless. https://discussions.unity.com/t/481379
You’ve also provided basically no context, like what objects you’re talking about or the exact outcome you want. You should start a new detailed thread.