#need help with enemy spawner
18 messages · Page 1 of 1 (latest)
your "hole" variable is null for the spawned enemy
if you're assigning the hole variable manually for the enemy you added on its own, then you can do the same for the enemy spawner and do "enemy.hole = hole" when instantiating the enemy
I'm not entirely sure where you mean, but I tried adding that code into several different places and none worked.
I realized that the "hole" node is null, but I'm not sure why, or how to make it NOT null
on which node did you add the enemy with add_child?
is it on the same level as the enemy that you've added directly on scene?
that might be the problem since you've hardcoded the hole's node path on your enemy's script
You should see a warning in the debugger window then where it says it can't find the node at that location
Yeah, that was the issue haha, so I just changed the path to be relative to the spawned enemies. Now it doesn't break immediately 🙂
Although I can spawn the enemies now. I'm still having another issue.
When the enemy touches the hole in the center, I'm using the queue_free() function to make it despawn. The issue is that i can't spawn multiple enemies at a time, and after the first one "dies" and the game tries to spawn in another, I get this error:
found out I can't "add_child" after the instance has been freed, so is there a different way of doing that?
You can set visibility to false to hide it and give an illusion of being destroyed if you want to reuse the node again
Setting visibility to false will also disable physics interaction for that node if I'm not mistaken
unfortunately, it doesn't disable physics interactions, but either way, I would like to have multiple enemies at a time.
after thinking about it, I don't think my problem is with making the enemies despawn
I think I just need a way to make multiple of the same instance at the same time