Greetings everyone, I am struggling a bit with Event Dispatchers and casting - specifically, telling a box trigger it is okay to spawn an enemy if a particular actor has been destroyed (i.e. a key for a locked door). I don’t want to player to trigger spawning the enemy until after they picked up the key.
I have been working on this for two days and my brain is full on spaghetti to the point I keep talking myself in circles about what “should” work. The way I understand it, The CALL Event Dispatcher should come from the key to be picked up, and should be CAST to the BP of the Box Trigger. Then the Box Trigger should listen for the BP_Key via BIND, create a custom event off of that, and from there set something like “picked up key = true” then I can use a condition branch to trigger the spawn of the enemy upon end overlap.
Here is a screengrab of the KEY blueprint…even if the cast is wrong I struggle with what to set as the OBJECT here.
Here is a screengrab of the Collision BP (Wallace is a character name if that helps avoid confusion) I have added PRINT STRINGS to help debug but I can never seem to get anything past 2) to trigger
Move the ‘destroy actor’ to the end: How are you supposed to run the rest of the code if you just destroyed the actor running it?
Then it might work.
But dispatchers is a crazy way to do this anyway. I’m not saying you’re crazy, I’m just saying I understand there’s probably a -NUTS!- youtube tuut out there with this in.
Dispatchers are for talking from one actor to many, not the case here.
All you have to do is
Pickup the key and set a ‘has key’ bool in the player
In the overlap volume, check if the player has the key
Boom, that’s it.
If you want to not be reaching into the player code from the overlap volume, then you can do the check with interfaces.
Thank you very much for taking the time to respond to this. So if I bring up Event Interact within the player BP, then on Pick Up Key I can set a ‘has key’ bool as you describe. Then do I need to cast to the overlap volume to be able for it to get the code and check if the player has the key?
Thanks again for the assistance! A community hero indeed!
Other way around. The volume in the box trigger, casts to the player, to check it is the player, and then checks the bool.
You can either do that by ‘reaching in’ to the player after the cast, or by making an interface call to check it. Try the cast first, to get it working, then move to the interface
Thank you for all your help. To be honest I still struggled with this, so I am going to have to go back and do my homework a bit on casting. i think I am constantly getting bind vs call mixed up to your point.
That said, I was able to get around it - instead of having the player bp check to see if conditions were met, within my interact system I told a specific key BP to upon actor destroyed to spawn a trigger box at a specific location, which would then spawn the enemy. Therefore, if you haven’t picked up the desired object the spawn trigger wouldn’t even exist, which accomplishes that same goal.