All Questions

Community

n
mateo nadal

Invalid get index 'name'(on base: 'null instance').

onready var state: State = get_node(initial_state) setget set_state

onready var _state_name: = state.name


The error happens on the second line.

  • Nathan Lovato replied

    Seems like a change due to Godot 3.2. You can leave the _state_name variable empty then. The set_state function will take care of initializing it:

    var _state_name := ""
    
  • n
    mateo nadal replied

    Thank you for the quick reply.

    Tried that now I get "Attempt to call function 'enter' in base 'null instance' on a null instance."

    func _ready() -> void:

    yield(owner, "ready")

    state.enter()


    Error happens on the third line.


  • Nathan Lovato replied

    Ah, it seems like you're not getting any state node. So the error is most likely either that you didn't set the initial state in your state machine, or you didn't set a correct path.

  • Nathan Lovato replied

    Ensure that initial_state is set in the inspector and it references an existing node of type State.

  • n
    mateo nadal replied

    That was it, thanks!