Invalid set index 'animation' (on base: 'Nil') with value of type 'String'

Godot Version

Godot 4


Im working on my game where you have to get to the endpoint. When you get to the end point it will play an animation and print end game to the console. I have a gameManager node.
Heres the game manager code:
extends Node
@export var animated_sprite2d: AnimatedSprite2D
@export var player: CharacterBody2D

func endLevel():
print(“End Level”)
player.animation = “Disapear” (This is the animations name)
await get_tree().create_timer(5.0).timeout (This is going to halt it until the animation finishes
print(“End again”)

Here is my endPoint code:
extends AnimatedSprite2D
@onready var game_manager = $“…/…/…/GameManager”
@onready var player = $“…/…/…/Player”
@onready var animated_sprite_2d = $“…/…/…/Player/AnimatedSprite2D”

func _on_end_point_body_entered(body):
if ( == “Player”):

Whenever i run the game and touch the endpoint it should play the animation and print to console but it crashes with the error in the title.

Here is how i arranged the nodes if that helps:

Make sure to paste your code formatted with the </> code block button like so

type or paste code here

# player is not an AnimatedSprite2D
player.animation = "Disapear"
# try this!"Disapear")

Oops, i was a dunce lol, i had the bottom code except the .play, thank you, your the batman of godot problems, second problem of mine today you solved

scratch my first reply.
I got a new error when i did“Disapear”)

Cannot call method ‘play’ on a null value.

the exported animated_sprite2d must not be set, make sure to assign in the game manager’s properties from the inspector.

@export var animated_sprite2d: AnimatedSprite2D

If i change the name of the Node do i also change it here?

You will have to re-assign it if you rename the variable. Godot should handle it if you re-name the Node.

How do i assign it in the game managers properties from the inspector?

Click on the game manager node, check out the inspector on the right, you will see a new section for all of your @export’d variables. Click Assign on Animatied Sprite 2D and select the player’s animatied sprite.

This is all i see

It won’t show up if there is a syntax error or if the script hasn’t been saved since adding the @export, I don’t suspect the latter to be true so do you get any error without even running the game?

I do not get any error without running the game