![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | jevans |
This came about while I was setting up a state machine.
The state machine includes the line:
class_name StateMachine
and the various states (which are all children of the FSM all include this line:
var fsm: StateMachine
From what I’ve seen of other peoples’ state machines, this is pretty common.
But when I first open godot, it throws the following error on all of of the states, and if I try to run it, it crashes with the same error message:
Parser Error: The identifier "StateMachine" isn't a valid type (not a script or clas), or couldn't be found on base "self".
After clicking back and forth between the nodes for a minute, the engine suddenly recognizes the class_name declaration and works just fine.
This leaves me with a weird situation – I don’t know if my code is broken, but it’s not working well enough to share, because it’s unreliable. Is there a trick to getting this to play nice? Is it a known bug? How can I get Godot/my game to play from a cold start without crashing with this error?
Thank you for any advice you can provide.
Have you instantiated any instances of StateMachine? Or are you just using the type declaration?
var fsm: StateMachine
doesn’t instantiate an object, it just tells the editor that fsm
has all the attributes of a StateMachine, so you get little boxes while editing scripts to select member properties or methods. You need to instantiate a StateMachine via fsm = StateMachine.new()
DDoop | 2021-01-05 12:30
Thanks! I haven’t but I will try it and see if it fixes this issue. Since I’m not super clear on the proper usage or on whether this has changed since the tutorial I followed was written, would instantiating be the right move for this: https://gdscript.com/godot-state-machine ?
It’s basically what I used for my state machine.
Thank you for your help!
jevans | 2021-01-06 04:05