Node not found error when i use get_node

Godot Version

Godot 4

Question

I am working on my game and i’m trying to get the character to set its animation to “Disappear” when it touches the endpoint. When i do, however, it crashes the window and gives me a Node not found error.
Here is the GameManager (What i use to control the games variables and such) code:
extends Node

var player_animated

func endLevel():
print(“End Level”)
player_animated = get_node(“PlayerAnimated”)
player_animated.animation = “Disapear”
await get_tree().create_timer(5.0).timeout
print(“End again”)

Here is the end points code:

extends AnimatedSprite2D
@onready var game_manager = $“…/…/…/GameManager”

func _on_end_point_body_entered(body):
if (body.name == “Player”):
GameManager.endLevel()

Node pathway:

Too many ..., if you’re working from that node it’s one to Player, and two to SceneOne

That broke it even further my guy, that part works fine, the function runs until it needs to do the .animation part then it crashes

hi again, i think i told you how to get the right node of GameManager

1 Like

Please do not call me a guy :smiley:

It not the GameManager i dont think, the script and function runs up until the player_animated.animation = “Disappear” then it says the player_animated node cant be found

My bad

1 Like

i think below is the fool proof way to get the GameManager on any node you want to get it (as long as the GameManager exists as the direct child of the main scene):

replace to this:

@onready var game_manager = get_tree().get_root().get_child(0).get_node("GameManager")

other than this way, you can just add your GameManager into a group as “game_manager”

then you just need to get the GameManager node like this

@onready var game_manager = get_tree().get_first_node_in_group("game_manager")

ok i see what’s wrong

change this to:

player_animated = $"../Player/PlayerAnimated"

you really need to use signal with parameter something or group to make it easier for you to get the right node you need

1 Like

Still has not worked. I honestly dont know what is going on.


It keeps saying that the node cannot be found.
Heres the node list again:

did you queue_free the player?
what exactly the error said?
did you add the GameManager else where? because i see you have SceneOne? there’s scene two and three?
if there’s Scene one and two and three, you simply cant use Game Manager node to find specific node like this, because you may put the player differently from one scene to another
i suggest to use Group, add the player to group of “player”
then get first node in group like i shown how to do it with game_manager

if you want though, you also can add @export var player_node:Node
or @export var player_animated_node:AnimatedSprite2D
this to Game Manager Script, then assign it through Inspector Dock

1 Like

I am just trying to get the animation to play. The error was:
E 0:00:03:0815 GameManager.gd:12 @ endLevel(): Node not found: “…/Player/PlayerAnimated” (relative to “/root/GameManager”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1652 @ get_node()
GameManager.gd:12 @ endLevel()
EndPointAnimation.gd:13 @ _on_end_point_body_entered()

There is only one scene, I just named it that way because i play to make more scenes.
There is only one GameManager
edit: Code works perfectly fine when i # out the player_animated.animation = “Disapear”