System Disabled Callback

Would there happen to be a callback or event to listen for when a system has been disabled/enabled?
By disabled I more so mean the method the EntityDebugger toggles.

I was trying to write a websocket system, but I’d like the system to close its connection when it is disabled.

You could derive from EntityDebugger and from SystemListView and create your own events.
Or you could check in the systems update method if its enabled via .Enabled

1 Like

OnUpdate isn’t called if Enabled is false though, so how exactly would that work out? And the View classes are just queries per individual systems. That doesn’t exactly help per se with an “Hey I was disabled” without making another system just to purely observe changes.

Right now there is no nice way of doing that. Only checking from another system. But I think it makes sense to add.

We have two ways of enabling / disabling. One is explicit enable / disable. The other is implicit based on no entities being relevant for the system. In which case we just dont call OnUpdate as an early out.

What would you optimally like to see happen in either of those cases? Do you have a proposal for an API you would like to see in the form of usage code you would like to optimally write for your use case.

With systems being able to be disabled and enabled, it would make a little bit of sense for them to be consistent with the existing GameObject and ScriptableObject in the sense that they have some method callback or an optional override-able method similar to OnCreateManager.

In this particular scenario, I’d like it to clean up the socket system to disconnect and reconnect gracefully as needed.

[AlwaysUpdateSystem]
public class SocketSystem : ComponentSystem {
    private override void OnEnable() {
        OpenConnection();
        StartListeners();
    }

    private override void OnDisable() {
        CloseConnection();
        StopListeners();
    }
    // Omitted arbitrary socket code
}

However, that is just a small use case and may be lacking in some nuances to the direction that Unity is heading. Because I am still learning the core concepts of Data Driven Design, I’m not sure what would be the best approach to it, though truth be told, I would likely either just add a method call to the existing Enabled property or at the end of a frame have something inform any system of state changes.

1 Like