[Input System] Callbacks Not Firing
Solution
Unity 2019.1.x - Unity 6.3.x
Published Thu, Mar 26
Unity lifecycle methods are case-sensitive. If OnEnable or OnDisable are incorrectly capitalized, the InputAction subscriptions within your script will fail to execute. This prevents input-specific logic from running even when the GameObject is active and logs suggest the script is loaded.
The issue is typically caused by incorrect capitalization of the OnEnable lifecycle method. Unity relies on exact naming conventions to hook into the engine execution pipeline via reflection. If these methods are defined with lowercase letters, the engine will not trigger them.
To resolve this:
- Rename
onEnableto OnEnable andonDisableto OnDisable in your script. - Call the
Enable()method on theInputActionto activate it within the engine. - Register callbacks to the
started,performed, orcanceledevents of theInputAction. - Unsubscribe from the same events in OnDisable to maintain memory safety.
Additional Tips:
- Use
performedfor most gameplay logic to ensure the action has reached its threshold. - If using
InputActionReference, ensure the asset is assigned in the Inspector. - Always call
Disable()on the action in OnDisable to prevent input being processed while the object is inactive.
TL;DR
Lifecycle methods must be correctly capitalized as OnEnable and OnDisable to register and unregister InputAction callbacks successfully.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.