New Input System - Stopping the player input

FYI for folks who are interested. Turns out stopping the player input with the new input system is really easy. You just need to run the Enable() and Disable() methods on the map.

For example, I have a my Input Actions stored in a variable called controls and my player controls are a map called Player. So to disable those controls you call

controls.Player.Disable()

and to enable

controls.Player.Enable()

Now to run these from the cinematic you just need to subscribe to a method that implements these commands. For example,

private void Start() {
     GetComponent<PlayableDirector>.played += StartCutscene;
     GetComponent<PlayableDirection>.stopped += EndCutscene;
}

private void StartCutscene() {
     InputManager.instance.controls.Player.Enable()
}

private void EndCutscene() {
     InputManager.instance.controls.Player.Disable()
}

Where InputManager is a singleton where I have put all my interactions/delegates with the input system.

The one thing I am not sure of is where I need to unsubscribe these callbacks to the PlayableDirector. Should it be in OnDisable(), OnDestroy(), or somewhere else?

1 Like

Ideally, subscriptions to events should occur in the OnEnable() and OnDisable() callbacks

void OnEnable()
{
    GetComponent<PlayableDirector>.played += StartCutscene;
    GetComponent<PlayableDirection>.stopped += EndCutscene;
}
void OnDisable()
{
     GetComponent<PlayableDirector>.played -= StartCutscene;
     GetComponent<PlayableDirection>.stopped -= EndCutscene;
}
2 Likes

Privacy & Terms