• 2D
  • How to properly reference a node?

I have been partly following a tutorial and I got stuck here where animationTree is null, despite being in an onready var.

The error I am getting is: Attempt to call function 'get' in base 'null instance' on a null instance.

Am I doing something wrong? Do I need to provide more information?

I suggest to check if the script you edit here is actually the one attached to the "Player" node.

You probably want to set animationState in the _ready function rather than using onready since animationTree is also being set using onready. Personally, I'd suggest setting both variables in _ready, just so you know that they are both set and their functions usable:

var animationTree : AnimationTree
var animationState

func _ready():
	animationTree = $AnimationTree
	animationState = animationTree.get("parameters/playback")

Though as @NeoD mentioned, you probably want to make sure that the script is properly attached to the Player node.

Thanks for your help everyone but I found the solution. Unfortunately I forgot set this script as an AutoLoad so it was being called before the onready.