Godot: AnimationNodeStateMachine: Can't travel to '' if state machine is not active.

Created on 17 May 2019  路  9Comments  路  Source: godotengine/godot

Godot version:

3.1

OS/device including version:

Windows

Issue description:

Whenever I try to call the method travel() on AnimationNodeStateMachine I get the error:
'Can't travel to '' if state machine is not active.'

  • The AnimationTree is active
  • The travel() method gets a valid parameter (one idle and one idle_down for example), but start_request gets reset right before the error is printed, that why I get an empty string.

The AnimationTree consists of 3 StateMachines
image
each of them are structured like this:
image
This is my scene structure:
image
And this is the script on Player:

extends KinematicBody2D

export (int) var walk_speed = 200
export (int) var run_speed = 300
export (int) var frames_till_idle = 300

var state_machines = {}
var curr_speed = 0
var move_state = "idle"
var direction = "down"
var velocity = Vector2(0, 0)

func _ready():
    state_machines["main"] = get_node("AnimationTree").get("parameters/playback")
    state_machines["idle"] = get_node("AnimationTree").get("parameters/idle/playback")
    state_machines["walk"] = get_node("AnimationTree").get("parameters/walk/playback")
    state_machines["run"] = get_node("AnimationTree").get("parameters/run/playback")

func _physics_process(delta):
    _check_movement()
    move_and_slide(velocity)

func _check_movement():

    velocity = Vector2()
    if Input.is_action_pressed("move_down"):
        set_direction("down")
        velocity.y += 1

    if Input.is_action_pressed("move_up"):
        set_direction("up")
        velocity.y -= 1

    if Input.is_action_pressed("move_right"):
        set_direction("right")
        velocity.x += 1

    if Input.is_action_pressed("move_left"):
        set_direction("left")
        velocity.x -= 1

    if velocity.length() > 0:
        if Input.is_action_pressed("move_run"):
            set_move_state("run")
        else:
            set_move_state("walk")

    print(move_state) # prints 'idle' for example
    print(move_state + "_" + direction) # prints 'idle_down' for example
    state_machines["main"].travel(move_state) # prints above error
    state_machines[move_state].travel(move_state + "_" + direction) # prints above error

    velocity = velocity.normalized() * curr_speed

func set_move_state(new_move_state):
    match new_move_state:
        "idle": set_speed(0)
        "walk": set_speed(walk_speed)
        "run": set_speed(run_speed)

    move_state = new_move_state

func set_speed(new_speed):
    curr_speed = new_speed

func set_direction(new_direction):
    direction = new_direction
bug core

Most helpful comment

This will happen if you have not selected auto-start for one of your nodes in the statemachine root

image

All 9 comments

I have the same error from what seems to me to be very basic usage. I'm following this video:

https://www.youtube.com/watch?v=0bq2OIjHxk4&

Please, can you provide a demo project to facilitate debugging?

Ok, so the system not behaving properly was actually a typos in the state_machines paths, I swapped walk and run.
I made a debug project, these errors are still popping off, most of them at the start of a playtest.
AnimationNodeStateMachine Debug.zip

'Can't travel to '' if state machine is not active.'

Well, this message is a bit strange, in fact, you need to check if your state machine is already playing before calling travel, like this:

if state_machines["main"].is_playing():
    state_machines["main"].travel(move_state) # prints above error
if state_machines[move_state].is_playing():
    state_machines[move_state].travel(move_state + "_" + direction) # prints above error

This happens because, when you start the game, only root state machine will be active, sub state machines are only activated after traveling to it.

Hmm alright... So the only "bug" really is, that the start_request in the source code is cleared before the error message is displayed in animation_node_state_machine.cpp in line 317

How did you solve this ?

I just had this issue today, and was only able to solve it by deleting all unused files, all .import files and the entire .import folder. I didn't alter my script that controlled the animations, so it wasn't due to any typos or mistakes in the code. I'm not sure what went wrong, but the issue remained when I removed the AnimationTree node and then added a new one.
I don't have a project I can share unfortunately as I'm working on a project for a client and don't know how to reproduce...

But can confirm the bug definitely still exists on the latest stable build (3.2.1, Windows 10).

This will happen if you have not selected auto-start for one of your nodes in the statemachine root

image

Was this page helpful?
0 / 5 - 0 ratings