I followed a tutorial and i have a door which will open when all the enemies are dead, however I noticed that if i have another door (same blueprint) and I spawn more enemies in and kill them, the door doesn’t open? Could someone explain why and help me make it so this blueprint works on multiple doors, thanks.
This tutorial hangs this on the GameMode which acts as the bridge between two events: Killing and door opening.
I grabbed this snip from the video closer to the end, notice the array that follows the “Get All Actors Of Class” Node. It only refers to the first actor within that array, additionally, notice the “Do Once” node which will execute the code once and prevent it from firing again.
The combination of these two nodes would prevent any more instances of that door from opening.
If you want to just keep opening doors based on a kill count total, then you’d want to execute “GetAllActorsOfClass” in BeginPlay (or after all doors are loaded), then get that array and increase the Array Index with every execution so that you’d keep getting subsequent doors from that array.
If you wanted to do something a bit more complicated like say… certain enemies groups open particular doors, then you’re looking at keeping track of those groups using tools like… GameplayTags or Tags then counting those tags instead.
Using GameplayTags or Actor Tags is a great way to reuse Blueprints and give them unique identities during gameplay, you’d then be able to use nodes like “GetAllActorsOfClassWithTag” to narrow down the search for the door you want to open specifically.
This isn’t a huge project for school so simply increasing the Array Index will be fine, and after trying to get some custom events in the right place it works! So thanks a lot, although I do have one question as im not sure if there are any other potential causes for this issue ill find later on. But for some reason when I hit compile and play the project, the first time it runs it will open the very last door first? and then continue as normal afterwards. However when playing the project every other time after the previous one they open in the correct order? If you don’t know its fine id just thought I would ask since it seems to be a weird bug or issue.
Thanks again for replying earlier I was stumped on this for some time.
The GetAllActorOfClass node does not guarantee any type of order.
IMO if the enemies are already in the level, the door should be binded to a dispatcher in each that tells the door when they have been killed. If the enemies are spawned by a manager then that manager can handle the communication.
It should be event driven, not this from the video you posted:
So how would you do that then? As I realized what you mean now as when I reopened my project the doors are opening in a completely different order. And if im being honest I literally have 0 idea on how to fix this/make it so they can open in an order i want them to.
The enemies aren’t in the level by default and are spawned in when walking through a collision box which is the entrance to each room, then once an enemy is killed it calls an “Enemy Dead” Custom event (was originally a event tick), checks to see if enemies alive is 0 and if it does open the door, that’s how its supposed to function anyway.
Triggerencounter is the first function executed when the referenced trigger volume is overlapped by the player. It binds OnEnemyDestroyed function to the OnDestroyed of ever spawned actor:
I’ve got all the code in my project and it seems to be working completely fine! Thank you so much as this was all extremely detailed and has helped me massively, as this is one of last complex mechanics left I needed to complete in this project (All that i know is left is a mechanic to swap between 2 Guns which ill start tmrw)
Thanks once again, this has been extremely helpful as I wasn’t ever gonna figure this out on my own.
Hey, I know this is an old thread but it helped me set up the enemy spawning and the door to the room closing until all enemies are killed, so i would like to thank you for that, but I have run into a problem I don’t know how to fix: I have a procedurally generated dungeon that is made up of pre made rooms and a door BP that spawns connecting the rooms, but the Manager BP only work when I manually place it into a level and assign the default door BP and trigger volume variables for spawning the enemies, it doesn’t work when everything is spawned in during dungeon generation. For some context the player would go from room to room and each one would lock all exits until all enemies that have spawned inside the room are killed. Any help would be much appreciated, thanks.
My first guess would be that the generator could dynamically establish references between the room manager and its associated doors.
Another idea is that instead of direct references, a messaging or event-based system can be implemented. Coms would be via unique IDs or channels. The manager would send a message when the conditions are met, and the doors would listen for that message. The Lyra project has a messaging system plugin that you could check out. E.g.: all actors of a ‘block’ could be assigned an ID and the rest of the message would be the event. Something like a string ID_MESSAGE could be passed.