Simple animation problem

Godot Version

Godot_V.4.2.2

Question

I have a player and a simple animation that just changes players modulate,but every time i try to play it it says:
Attemp to call function ‘play’ in base ‘null instance’ on a null instance
Like what am i doing wrong :sob:

Can you please share your code and scene tree? We don’t have enough information to help solve your problem.

You’ll have to help us out a bit more here; how do you reference and call play on the AnimationPlayer node? Likely, that reference is null as the error states - perhaps it isn’t ready yet or the way the script references the node is incorrect.

In the player script i just type
Func _ready()
$Animatiplayer.play(“die”)

I see the problem. You don’t have a colon after the _ready(), and you reference the animation player with $Animatiplayer, when it should be $AnimationPlayer. You forgot the ‘on’ in the node get, causing the player node to not be able to find the child, so it will throw an error when you call play() on ‘null’.

Here’s some similar code from one of my demos.

setting the anim variable saves typing $AnimatedSprite2D repeatedly

func _physics_process(delta):

var anim = $AnimatedSprite2D

	if velocity.x == 0 and velocity.y == 0:
	anim.play("idle")

Similar code won’t do. We need the exact code in your project that is causing the error. Even a simple typo can cause a problem like that.

@Opalion I was responding - I’m not the person who raised this. :slight_smile:

sorry, my bad

1 Like

@Opalion All is fair in love and game development