SS3D
SS3D copied to clipboard
InputSystem in OnStart and OnDestroyed
InputSystem subscriptions should be in OnEnable and unsubscribes should be in OnDisabled in all files, so input actions won't trigger disabled scripts. Currently this causes null reference erorrs, because OnEnables in subscribers are called before OnAwake in InputSystem. Figure out how to fix this without changing the code execution order.
@iamteapot422 does it needs to be in all files ? Only those dealing with controls I assume ? It'd be useful to have a bit more information on what causes the null ref errors too.
@stilnat yeah, its needed only where subscriptions to inputs are present. Null ref is caused because subscriptions in OnEnable are used before InputSystem initialization
@iamteapot422 Ok thanks, well a possible solution I have in mind would be to have an Interface, IInputRegistering, with at least 3 methods :
- HandleInputSystemReady() -> Suscribe the following method to an event fired by the input system when it's ready, called in OnEnable. Also check a bool on InputSystem to see if it's already ready, because we might want to suscribe in the middle of the game and the event will fire only once.
- SuscribeToInputs() -> triggered by events on Input system when ready. Suscribes inputs.
- UnsuscribeFromInputs -> Should be called in OnDisable of the script. Unsuscribe inputs.
Not perfect but gives some structure on the way to register inputs, and an interface where we can write the doc.
@stilnat the real problem is that SystemLocator registers InputSystem later the OnEnables are called