Sharing variables between LevelBP and HUD.

Hi everyone !

I’m having a really big missunderstanding problem with blueprints/level blueprint/hud blueprint communication.
I’ve tryied to check the help, tutorials, but I really don’t get it.

For example, in my pinball game, I have a trigger, that check for overlapping actor, if my ball touch it, I destroy it, then spawn a new one. I have a variable set to 3 at the begining, and a condition that compar my variable with another number (0), if it’s lower, it spwan a new ball, and remove 1 to the variable, until 0 where I don’t kick anymore balls. everything is working great.

Now I would like to display that variable in the hud, so we can see how many balls we still have :slight_smile: Pretty genius right ?

Well I’m not genius enough to bring that variable to another blueprint, I even don’t know how to share anything between level blueprint and class blueprint…

Could someone explain me how to do to share a variable between every kind of blueprint we use in the game ?
Or at least how to get my variable from the level blue print to the hud blue print ?

Sorry if it’s super easy and have been explained somewhere else a million times, I’ve read many comments and videos, and I still don’t get the logic.

Many thanks !

.,

Depending on what you are trying to do you can CASTTO a blueprint or class and have access to variables. if you are casting to variables in a C++ class they have to be exposed to blueprints.

Once you cast to you can pull off the cast and check or set a value for a variable.

Hi,

I’m using blueprint graph, I have a variable I want to use from my level blueprint to my HUD blueprint, I’ve tried to get the wire from my variable and type cast to, but I only get cast to int/bool/etc… , I don’t have anything referencing a cast to blueprint .

To be simple, I want a variable from the level blueprint, to be accessible in any over blueprints, including my HUD blueprint.

Hey ,

The Level blueprint would not be the ideal place to store any game-play relevant variables that you want accessed somewhere other than the Level blueprint. A better option would be storing those variables in a GameMode blueprint, which is much more easily accessed than the Level blueprint. You can call Get Game ModeCast to YourGameMode to access any variables you store in that blueprint.

Hope that helps!

-Steve

Hi Steve !

Thanks for your reply, the problem is I used Level BluePrint for my game mechanic because I don’t know how to “get” actors from my scene into the blueprint (except the level blueprint that allow me to bring the reference I select in the scene directly to my blueprint).

If you could tell me how to bring any actors that are in my scene to any blueprint/gamemode blueprints, I’ll be thanks full for the rest of my life ! :slight_smile:

Hey ,

You can use the Get All Actors of Class node to get an array of all the actors in your scene that are of that class.

Cheers,

-Steve

Hi Steve,

I’ll give a try later today, I haven’t got the chance to work with arrays but I’ll check the help.

I’ll let you know, thanks a lot !

Hi Steve,

I’ve been trying to Get All Actor of Class in my HUD blueprint, but I don’t understand arrays workflow, I have 6 coins in my scene, the array in all of them, ow I don’t know how to say every times I hit a coin, add one value to the result :confused: I’m sorry I’m not good at all in programming, I don’t want to go futher in my game until I found out how to make each blueprint to talk to each others.

I’ve been looking to the Ninja project in the market place, but it’s difficult to trace how they connect coins to the hud.
Cheers.

Hi,

I found a way, just been looking closer to the ninja game from market place and now I get it !

Thanks !

Create an int variable in your HUD blueprint then just use a blueprint interface to tell it how many balls you got left. This applies to all sorts of communication between your blueprints.

You can simply get all actors of the ball class and ask for the length of the array and send it to the HUD via a blueprint interface.