Instantiate object at location of parent

Godot Version

4.2

Question

I’m new to Godot (coming from Unity) and I’ve run into a problem that has me stumped. I’m trying to spawn objects from an array at a random location from an array of points. My code looks like this:

image_2024-02-08_075819454

This spawns, and it reparents it to one of the spawn points in the inspector, but the object still spawns in the middle of my main node . How can I get it to spawn at the location of its new parent?

try

new_instance.reparent(spawn_points.pick_random(), false)

Reparent has a second argument that, by default, maintains the global position of the node. You can set it to false and that should give you the behavior you need. I’d agree it’s a little counterintuitive coming from Unity.

1 Like

Worked perfectly! Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.