Set variable in level blueprint

i’ve read half of google and i still can’t figure out how to set/get same variable in level blueprint and another one

It sounds like you want casting, this youtube video helped me understand exactly what it is and most importantly what the object node is for and why it’s important. - YouTube

With casting you’ll be able to get and set or otherwise perform actions as what ever blueprint you’re casting to from inside a different blueprint of the same class.

So when your ball is destroyed you would want to cast to what ever blueprint you’re storing that variable in, from there drag from the “as (name of your blueprint)” pin and you can get or set the variable you want.

Assuming you have the right object pin and the cast succeeds that should do what you want.

PS: For casting from a class blueprint to a level blueprint that requires Event Dispatchers if I’m not mistaken. This video might help you with that one. I haven’t experimented with them yet so best of luck to you. UE4 Event Dispatchers - YouTube

In level blueprint i have variable “amount_balls_on_screen”, when i spawn a new ball i increment this value by 1, next i have “player” blueprint where if ball collides with player i want to decrement “amount_balls_on_screen” in level blueprint.

How can i do that? (set the variable)

Hi.

I’ve never tried to count elements in the level, but I can explain you how varibles work.
I wrote on screenshots and I hope you can read anything.

You can add as much variables as you want and you can use each of the various types avaible.
in your case i’d use an integer, but even float is good (float as a type is heavier than integer)

obviously you can set a new value of the variable as many time as you want

I don’t know how much you know about programming so I explained it a bit too much but it could be useful for others too.

it’s totally not what i asked for, my question was how to set (change,modify) variable in level blueprint from other blueprint

http://i.imgur.com/CuIUYKl.png

i increment my variable in here

http://i.imgur.com/gyTtOmh.png

and i want to decrement it in here

http://i.imgur.com/nAfi6dF.png

I’m sorry. Misunderstood your need.
This is a thread about setting a "comunication between blueprint https://answers.unrealengine.com/questions/21386/communication-between-2-blueprints.html?sort=oldest

Just in case someone lands here someday looking for an actual solution. What you need to do is use event dispatchers, it’s the only way to communicate from any other blueprint to level blueprint. You’ll create an event dispatchers on some blueprint, like the one you want to change that level variable. Then you bind the level blueprint to that event dispatchers and hook it up to an event. Finally you can actually set the variable from that event within the level blueprint

1 Like