Sharing Bool values across blueprints

So… I have a campfire BP that constantly loses fuel and eventually burns out. Once it does, it sets a bool named “FireOut?” to true to reflect that. The player has a sanity meter that drops when outside the range of the fire and is restored when in range (given that the fire is still lit). So, the player’s BP relies on information such as being in range of the campfire and the campfire being lit to determine whether to restore or continue to drop sanity. I have a cast set up to detect when the player is in physical range of the campfire (with a sphere collision) but the evaluation of the players sanity function constantly needs an valid bool from the campfire BP. I’ve tried using a cast for that but it requires a reference to the campfire object and I don’t know how to retrieve that; especially before the player enters the sphere collider of the campfire. I’ve been looking into blueprint interfaces and event dispatchers to see if there’s a way around this but I just cant seem to find anything. Is there another way to grab a reference right off the bat? Or am I going about this feature all wrong?

a simple way is to put the collision sphere on the campfire,
when FireOut is true disable the collision

now you dont have to check anything, if the character is in range and collision is enabled it will work

1 Like

This might not be the best way to do this, however, as a learning moment it will likely blow your mind. If you add a variable to your game instance, you can GET and SET it from anywhere. Just get game instance, cast to game instance, plug the get game instance into the cast’s target and get or set your variable. The simplest way to communicate between things when nothing else seems to work for you.

1 Like

This is nice and it definitely solves my problem. In the future, how can I feed variable values from one BP to another when things like sphere collision aren’t available to help cast?

storing variables in game instance always works and is a reliable way to communicate between BPs, ui etc.

1 Like

i cant really recommend the game instance unless you have a proper save/load system, its quick and easy for sure but
it creates dependencies, your actor no longer works without that specific GI
and it will get hard in the long run, if you’re managing 100s of objects over multiple maps and you have to remember which bool belongs to which actor etc.

much better to keep things as self contained as possible.

to answer your question about BP communication

  1. simple way GetActorOfClass but i dont really recommend that
  2. have a manager class, not unlike what DeepPixel suggested but could be map specific. this allows you to reference things placed or spawn in the level
  3. you can do a sphere trace around the actor and then use interfaces or casts.
  4. GetPlayerCharacter, so if you have a single player game the fire can reference the character rather than the character trying to track all fires
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.