Transitioning to the Dash State

I followed the code exactly as shown in this video … but Dash State is not being Activated for some reason. Where is the 5001 notification being sent to the DashState upon receiving the input from the keyboard?

Upon adding some debug statements … when a button is pressed the notification signature is more like 1000, 1001, 1002, 1003 etc.

Example…
Dash State Awaiting Notification …1002

The pseudocode would look something like this:

  • Player.cs: “Dash” key is pressed; call StateMachine.SwitchState(Dash)
  • StateMachine.cs: SwitchState confirms that the Dash state exists in the states array; if so, set currentState to Dash and call Dash.Notification(5001).
  • PlayerDashState.cs: in _Notification(), if the notification received is 5001, play Dash animation.

According to the docs, notifications 1002 and 1003 are just mouse enter/leave, which tells me that 5001 is simply not firing at all. The bullets I listed are in order, and I would check that control flow from beginning to end. If you still can’t find out what’s going on, it would be best to post the relevant code so we can have a closer look.

I figured it out… the video left out assigning the newly added state to the state machine “States” array … If you don’t do that, all you get is a null reference and the state never switches properly. Once I increased the size of the state machine array and add the new state, the Dash State started working as expected … struggled for a few hours figuring this out … but finally got it. Since the States are an exported field, this needs to be done in the Godot editor and not in Visual Studio Code. Thanks for your response.

1 Like

Makes sense that this was part of the issue. [Export] variables have excellent use-cases, but in my opinion, this isn’t one of them. Congratulations on powering through and finding the problem =)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms