[RESOLVED] How to use the same variable in differents BP?

I have 2 differentes widget blueprints where I have a switch button with ‘yes’ or ‘no’. The player need to hit ‘yes’ on the first BP before go to the second one, otherwise it’ll give false text if goes directly to the second without pass trought the first. If the player hit YES on the first widget BP then the variable “painting 2” is set to TRUE. But everytime I got to the second widget blueprint and hit ‘yes’ it give me FALSE instead of true.

There’s something I’m missing but I can’t figure out alone.

I’m very noob yet with Unreal Engine. I was trying to create a reference to use on the variable and I saw somewhere that ‘create a widget’ is the thing. About ‘IsValid’: which one I got use? There’s so many. I’ll try show what i’m trying to do

I’m using the widget blueprint to display this “press button yes or no” and then using remove from parent in order to remove from screen. Makes sense to me what you saying but I struggling to understand how to get the result yet.

So I’m trying to make a connection between these two widget blueprints from differents painting.

I’m appreciate your time answering me. I’ll try to read again and again till I understand everything perfectly haha

How do I promote the widget to a variable? By creating a variable reference to the widget? Like this?

Let me see… I need to create a variable reference to the widget and store them in some other place?

Like this?

Not chipping in. Just wanted to say this looks pretty neat!

Okay, I know you explained it but I’m still not quite sure what I’m looking at here.

First of all, on your second screenshot, you show that you keep creating a new widget every time the button is pressed, so if button is false by default, you will always get false there, because you are just creating new versions of the widget over and over again.

In order to create the widget once and then simply get the variables out of that widget, you may want to promote the widget into a variable and then use an Is Valid node to check if it already exists or not. If it already exists, then don’t create another one. You can also use the variable of that whole widget to access variables within the widget.

That is the most glaring issue I can see, but some other problems that may be present are the fact that you seem to be creating the widget after you clicked a button inside the widget, which indicates to me that you probably created another version of the widget somewhere else even before this (in which case you need to get that one’s variable instead).

And, also, when you remove from parent node in the upper screenshot, I’m not certain, but I’m think that might make the widget’s settings to back to default.

Hello! The thing is very simple. Widget BP 01 has its own variable and Widget BP 02 - another one. Moreover after you remove widget from parent then it will be deleted if no other objects reference it. One simple solution, that you can use - to store this variable in some parent container widget and set it on it.

Okay, thinking about this more:

I recommend you create both widgets somewhere and promote them to variables. Maybe the player character or game mode or some other outside source.

Then, in the second widget, cast to player character/game mode/wherever you put the variables, and pull out the widget variable for the first widget. And, from there pull out the variables inside the first widget. You probably can’t remove the first widget from parent though.

If you want to remove the first widget from parent, then you need to reverse: Have the bool variable inside the second widget, and have the first widget, on click event, do the cast and get the variable of the second widget and set the bool inside of it.

I hope this makes sense. I know it is a lot of typing.

Oh My Gosh )) Pictures are so stylish ))

That is really simple - create parent widget, add boolean variable in it. After that create two widgets that you mentioned above and keep reference to parent in both of them (also with variables). So now, you can access and change almost all from both of these widgets through reference to parent that they keep

That’s fine, everyone comes to this forum to learn! That’s the reason it is here. :slight_smile:

Let me see how to do this in depth…
I will do it from the main character, since most people have one of those already. If you are going to have A LOT of widgets like this, you may want to put them somewhere else, but this is just for example.
And, I’m going to keep using just two widgets to keep it simple. No childing.

Let’s create the widgets, widget variables, and your bool variable in your character for this example (I like Kahel18’s idea of keeping the variable even outside the widget :slight_smile: ). The easiest way to promote to variable is to right click the output pin and select promote to variable:

Then, in the first widget, you would cast to the place you put the variables (in this case the main character) to change them.

In the second widget, you get the variable.

Also, how to add the widgets to the viewport if the variable for them is somewhere else. (You may just be using an overlap for this on paintings, which is fine). I have used a custom event here just because I needed to attach it to something.

Thank you so much!!! It worked perfectly well the way I wanted!!! Thanks for your time and help, really!!! I was going crazy for like 3 days before try here and wow!

Thannksss :))

If is not too much to ask (since the worst part is over). Can you tell me what can i use to fire this animation after the switch is pressed? Is on the level blueprint this one

Ah. Yeah, that’s a bit of a unique thing about Level Blueprints. They are unusually difficult to communicate with! Most of the time you need to use an Event Dispatcher.

This video gives a good example about how to use them. :slight_smile: