Godot 4.2 AnimationTree returns null

Godot Version

extends CharacterBody2D

@export var SPEED = 100.0

@onready var anim_tree : AnimationTree = $AnimationTree

var direction = Vector2.ZERO

func _ready():
anim_tree.active = true

func _process(delta):

func _physics_process(delta):
direction = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = (direction * SPEED).normalized()


When launching the game the AnimationTree returns as null even though it is in the Player tree that the script is attached to.

Error: E 0:00:01:0028 Player.gd:5 @ _ready(): Node not found: “AnimationTree” (relative to “/root/Player”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1638 @ get_node()
Player.gd:5 @ _ready()


All I am doing in the main scene is instantiating the Player Scene.

Try :
Click on the Node player node and then click on the Script section. Later @onready var anim_tree : AnimationTree = $AnimationTree. delete and write again.

that did not change anything

Look at this


Create a copy " ctrl D " of AnimationTree, give it a different name and try using it. If it still doesn’t work, delete the AnimationTree and add it again.

It somehow fixed itself thanks.

1 Like