UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

architecture

[Input System] Callbacks Not Firing

Solution

input systemevent handlingproject architectureuser input

Unity 2019.1.x - Unity 6.3.x

Published Thu, Mar 26

Issue

 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.

Explanation

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:

  1. Rename onEnable to OnEnable and onDisable to OnDisable in your script.
  2. Call the Enable() method on the InputAction to activate it within the engine.
  3. Register callbacks to the started, performed, or canceled events of the InputAction.
  4. Unsubscribe from the same events in OnDisable to maintain memory safety.

Additional Tips:

  • Use performed for 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.