Help with creating enemy spawner

Godot Version

4.2.1 (Steam)

Question

I have already created and programmed an enemy for the 3D game I am making, and I am trying to create a spawner for it, so every 5 seconds the spawner creates an enemy. So I have a marker3d node where I want the enemy to spawn relative to where the spawner is, but for some reason when I place the spawner in a level I get an error in the debug console: E 0:00:00:0575 enemy.gd:68 @ pathfind(): Node origin and target are in the same position, look_at() failed.
<C++ Error> Condition “p_pos.is_equal_approx(p_target)” is true.
<C++ Source> scene/3d/node_3d.cpp:933 @ look_at_from_position()
enemy.gd:68 @ pathfind()
enemy.gd:50 @ _physics_process().
The robot does spawn, but for some reason it spawns in a set location far up and to the left of where my marker3d node is.

I am using GDScript, here is the code that instances an enemy scene:
func _on_spawntimer_timeout():
const ENEMYSP = preload(“res://scenes/objects/enemy.tscn”)
var robot_inst = ENEMYSP.instantiate()
robot_inst.global_position = global_position
add_child(robot_inst)

I have also tried placing a camera3d in the spawner scene and running the spawner scene with F6, and doing this will cause the spawner to work as expected. It only seems to bug when instanced.

Please, any help would be appreciated. I am new to Godot, so sorry if this is dumb or obvious.

in the enemy scene do you have any node3d as the root

global_position should be set after adding your robot instance as a child.
I believe the issue is that it doesn’t exist in the scene tree and therefore has no global position or doesn’t set it or something like that.

If I remember correctly this is something that is discussed to be changed for future version.

EDIT: Looking at some discussions, it looks like this won’t be changed as it is expected behaviour. Just remember to add_child first, then change global_position.

1 Like

Thanks, this was the problem! It worked fine after this!