Passing values from class BP to level BP through events
I have a class BP (Glow_Boxes - a simple box mesh) which contains logic to toggle whether the box glows or not. Shooting the box will cause it and surrounding boxes to toggle their glow. The method I am aiming for is:
Steps 3 and 4 are relatively easy by creating an array of Glow_Boxes within the area and then calling a custom event on them through a foreach loop. The difficulty I am having is passing information from the class BP to the level BP, specifically having an event in the level BP triggered through a class BP.
Is it possible to have an event in the level BP that is activated by one of any instances of a class BP? And then to allow the level BP to find out which instance called it?
One method I guess is to manually bind events in the level BP to every Glow_Boxes instance, but that only seems practical with a small number of meshes.
Thanks for any advice.
asked Aug 31 '14 at 04:39 PM in Blueprint Scripting
The way that I solved this problem was to create a collection and a collection manager in my GameState blueprint. I prefer to put level code there because it promotes re-usability across the full game and prevents me from doing smarmy things like trying to adjust the state of my systems over time inside of a "state-only" construct.
I created a Blueprint Interface for "GamePhase" listening (GamePhaseListener_INTERFACE) classes. Each of the objects that want to respond to changes to game phase implement this interface. When each object that will want to listen to gamephase changes is instantiated it registers with my GameState by adding itself to a list of actors (that ostensibly implement the interface) and whenever a change is made to the game phase (through a function on the game state blueprint) a message is "broadcast" to all implementing actors in that collection.
Doing it this way, rather than having peer-to-peer style event broadcasts easily prevents me from inadvertantly re-messaging a single message to any individual actor more than once. Recursion can be a real problem with blueprints because there is a total limit on the number of messages you can send in a single tick. In my case I also put some distance checking code on the listeners to see whether or not they even care about the event that was posted (which might be useful in your case.)
The GamePhaseChanged message that gets emitted includes the original actor that spawned the event, the position of the event instigator (if it was the player that triggered something but another object actually kicked off the event) and a collection of all objects that have so far responded to the event. (This allows me to pear down the list of potential responders as the event ages out in the system.)
answered Aug 31 '14 at 05:08 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here