Stuck on state machine

I was following a tutorial about how to make a 2d platformer and there was a part on state machines and I kept getting an error

"Invalid call nonexistent function ‘enter’ in base ‘nil’

I looked over the code and couldn’t find where I was going wrong. Can someone help tell me where I’m going wrong with this?

State .gd


The answer is simply that your current_state is nil or null (don’t ask me why Godot uses this weird nil), you can’t call a method of “nothing” right?

1 Like

You have to assign a State node to currentState before you use its methods and everything.

A tip for posting on the forum generally: instead of using a screenshot, paste your code directly with the code section format and include your scene tree when troubleshooting issues involving multiple nodes.

1 Like