function non existent but it does exist

Godot Version

v4.2.1

Question

i have a problem where i call a funtion in another node with script but it keeps saying that the funtion does not exist
area2d is the kill zone
image_2024-11-05_203232208
image
image

Make sure to paste scripts instead of screen shots.

Is Spawner a Global/Autoload?

2 Likes

Yes but calling them via the global autoload also did not work

You need to reference the node to call this method on it. Right now you are calling the methods as Class-methods
try this instead:

@export var spawner: Node

func _on_body_entered(body):
    spawner.destroy()
    spawner.respawn()

And make sure to go to the inspector and select the spawner as the exported “spawner”-variable

2 Likes

You do not want it as a Global/Autoload since that won’t be the same node as the one in your scene tree; try using an @export as @herrspaten suggests.

What is the exact error you recieve?

Also add your Camera2D to the player scene, or else it will be destroyed forever when respawning.

3 Likes

Your function is called “destoy()” and you are calling “destroy()”.

Did you check if that typo could be the problem?

3 Likes

i fixed the typo but now its is giving this error
E 0:00:04:0540 spawner.gd:15 @ respawn(): Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
<C++ Error> Condition “body->get_space() && flushing_queries” is true.
<C++ Source> servers/physics_2d/godot_physics_server_2d.cpp:654 @ body_set_shape_disabled()
spawner.gd:15 @ respawn()
killzone.gd:7 @ _on_body_entered()
and the player is not getting deleted

Im very new to Godot and trying to respawn my player when he dies without resetting the game so if there is an easier way that could also help