#I can't get access to a node in any way i've tried

1 messages · Page 1 of 1 (latest)

hexed bluff
#

Hey! So i've been learning it the engine for about 3 days and my experience has been great. But, even thought i've tried every single solution i could find, i can't get my player node within my instantiated enemy script.
my project goes about this: I have my main game scene and in it my camera2D node, my enemy spawner, my player character and a test enemy exactly equal to the one the spawner spawns in.
In my enemy_movement script i use move_towards() to change the enemy position into the player position. In this script i had been using a unique name to get the player (which was working just fine) until creating the enemy spawner , but now whenever the spawner instantiates a new enemy my game window crashes and godot says that the player node couldn't be found. After this i've also tried using find.children() which just returns a null value, and also tried moving the call to an _enter_tree() and to the _process functions but it gave the same result
The spawner script is incomplete (i still have to add an acceptable spawn distance) but it supposedly spawns things with no problem.

chrome escarp
#

Consider https://docs.godotengine.org/en/4.4/tutorials/scripting/groups.html . It's not reasonable for there to be a parent/child relationship between player and enemies

#

It's reasonable -- but onerous -- to expect the player/enemy common parent to associate them

#

So! Groups, and let the enemy query for their target.