Spawned objects are disappearing

Godot Version

v4.5.stable.official

Question

I have 2D project in godot whereI want to spawn a grid of objects.
I used script for spawning that worked in my previous 3D projects but the spawned grid is immediately deleted after spawning.

Here is the script fo spawner it self.

func spawn_entity(entity_id: String):
	var entity = general_entity_instancer.return_entity(entity_id).instantiate()
	chunk_manager.add_child(entity) #spawn do objektu
	print(entity)
	entity.set_global_position(self.get_global_position()) #globalni pozice

and here is a script for creating the grid

func spawn_grid(array):
	var default_pos = position
	for i in height:
		if i != 0:
			entity_spawner.position.y+=1
		entity_spawner.position.x = 0
		for j in width:
			if j != 0:
				entity_spawner.position.x += 1 
			entity_spawner.spawn_entity(array[i][j])
			print("X: ",entity_spawner.global_position.x," Y: ",entity_spawner.global_position.y)
	entity_spawner.position = default_pos

here is the script I am running in the main scene

func _process(delta: float) -> void:
	if !chunk_spawned:
		chunk_manager.spawn_grid(chunk_manager.array_functions.create_grid())
		chunk_spawned = true

Does anybody know what might be wrong?

Maybe somewhere when this process gets reset or something, it resets it directly, without actually letting it be. As in, the thing gets cleared, it builds the new grid, but then it gets cleared again after it’s built.

As far as I looked I can’t find anything in this code. Maybe you can give more details?

1 Like

I found it. It was actually just a stupid mistake on my part. Each of the objects I am spawning have an area which upon entering deletes the object. Since I didn’t change the collision layers and the objects are spawning right next to each other they just deleted themselves.

But thank you for the answer anyway. It made me look elsewhere than in the code I posted.

1 Like