I accidentally made a discussion about this but anyways I'll go ahead and write down what I put earlier. I have been trying to fix this issue for hours, watching videos, and the documentation. It is not the AnimationTree because it is active and a part of the child of the script holder. I can't seem to figure this out and it doesn't work with the void start function either.

extends KinematicBody2D

export (int) var speed = 200
var velocity = Vector2()
var statemachine 
func ready ():
	statemachine = $AnimationTree.get("parameters/playback")

func get_input():
		velocity = Vector2()
		if Input.is_action_pressed("right"):
			velocity.x += 1
			statemachine.travel("sprint")
			
		elif Input.is_action_pressed("left"):
			velocity.x -= 1
			
		elif Input.is_action_pressed("down"):
			velocity.y += 1
		elif Input.is_action_pressed("up"):
			velocity.y -= 1
			
		else:
			velocity.x = 0
			statemachine.travel("idle")
	
		velocity = velocity.normalized() * speed
	
func _physics_process(delta):
	get_input()
	velocity = move_and_slide(velocity)

Hopefully someone can help me. Also the strings are exactly the names of the actual playback animations.

It means Godot can't find the animation tree, probably because it's in another path.

So look here:

statemachine = $AnimationTree.get("parameters/playback")

That would only work if your animation tree is named "AnimationTree" and is a child of the current object attached to the script. If it's somewhere else, or named something else, then you would need to edit that line. For example, if the object is a sibling to the current script (on the same level) you could do:

statemachine = get_node("../AnimationTree").get("parameters/playback")

If it's somewhere far away you can also use an absolute path:

statemachine = get_node("/root/Game/Player/AnimationTree").get("parameters/playback")

In this case I made up "Game" and "Player" so you'd have to edit that ("Game" would be the root node).

@cybereality said: It means Godot can't find the animation tree, probably because it's in another path.

So look here:

statemachine = $AnimationTree.get("parameters/playback")

That would only work if your animation tree is named "AnimationTree" and is a child of the current object attached to the script. If it's somewhere else, or named something else, then you would need to edit that line. For example, if the object is a sibling to the current script (on the same level) you could do:

statemachine = get_node("../AnimationTree").get("parameters/playback")

If it's somewhere far away you can also use an absolute path:

statemachine = get_node("/root/Game/Player/AnimationTree").get("parameters/playback")

In this case I made up "Game" and "Player" so you'd have to edit that ("Game" would be the root node).

The animation tree is a child of the script holder. I stated it at the beginning of the question. "AnimationTree because it is active and a part of the child of the script holder." (probably shouldn't have used part) but the animation tree is a child of the script holder. Also my animation tree is named AnimationTree. I did try what you suggested, get_node("../AnimationTree").get("parameters/playback"), but it still gave me the same error. The kinematicbody2d is the script holder, and the animation tree is a child of the kinematicbody2d which has the script.

I see. Looking at the docs, it appears you forgot the state machine part.

var state_machine = anim_tree["parameters/StateMachine/playback"]

So in your case maybe try this:

statemachine = $AnimationTree.get("parameters/StateMachine/playback")

@cybereality said: I see. Looking at the docs, it appears you forgot the state machine part.

var state_machine = anim_tree["parameters/StateMachine/playback"]

So in your case maybe try this:

statemachine = $AnimationTree.get("parameters/StateMachine/playback")

Sadly I've tried both of those methods before. I have honestly been shaking my head over this. I just tried them again and still no luck. I even relaunched Godot.

It just keeps saying It cannot detect it. I may create a new project and see if it is just a problem with this current project.

Can you take a screenshot of your node tree in the editor?

@cybereality said: Can you take a screenshot of your node tree in the editor? Here, this also includes other things if it is helpful.

I see. The code never sets the state machine because you forgot the underscore:

func _ready():

@cybereality said: I see. The code never sets the state machine because you forgot the underscore:

func _ready():

That was it. I can't believe it took me that long to realize it.

No worries. Please feel free to mark my comment as answered. Thanks.

3 years later