Best way to spawn in multiple objects without overlapping

Godot Version

Godot ver 4.6

Question

Idk if the topic question properly described it but I didn’t know what else to do. Basically, I want to, over time, spawn in scenes with global_positions of Marker2Ds, but if one node is currently active at that Marker2D then choose another one to spawn at. This is what works best now, I have tried many other things but can’t get it to work properly and check to see if one is already spawned in that spot.

if game_active == true:
		var point = PressurePoint.instantiate()
		point.global_position = [$Marker2D.global_position, $Marker2D2.global_position, $Marker2D3.global_position, $Marker2D4.global_position, $Marker2D5.global_position].pick_random()
		add_child(point)
		start_spawn()

Store references to the spawned objects in the Dictionary, where the key is a marker node, and value is a spawned object. When selecting a marker, check if the value in the Dictionary for that key is populated with a spawned object, or null. If null - spawn the object, if not - select a different marker.

This is assuming your spawned objects don’t move, because you haven’t specified that.

In addition to @wchc comment, keep a hierarchy on the scene and every new node add it as a child to the proper scene marker. You can always query children from it

1 Like

Are there any good tutorials for this? I should also specify that once the object is deleted, that the marker 2D spawn point should open up again

I never found good sources about this topics, you need to dig a lot. I usually create objects related to a parent node or marker and create a method to clear children from a parent, that way i keep scene in order and even can use it in tools so the scene store them. This is useful for creating static levels as much dynamic ones.

I think what I will do is make a new scene that will function as a spawner. This should work and give me more control over how they work and fix some of the problems.

There are details not specified in your question that can make or break your approach. I have done a variation on this theme:

  • Create a list of markers/spawnpoints.
  • Find the first marker/spawnpoint that has no children.
  • Add your object to the spawnpoint.