Variables not being set to widget ref?

After checking whether the widget reference is valid, if its not I set the variable to the widget reference but then when called again the widget reference is not valid. Is there something I’m missing because I can’t figure out what’s wrong?

couple things you can try, use a cast to node to cast it to your widget class and see if the fails pin does anything, or just plug the variable directly into a print string and see what its printing, or depending on your situation, just get rid of the isvalid node ive had problems with that before

Haven’t tried casting yet but when printing the variables to screen I noticed that their values are lost, but they are being set successfully when i first create them. I don’t think this is supposed to happen, I see the same thing is happening on the multiplayer shootout example I used for reference.

I’ve found a possible solution, at least it seams to work, in each widget I have an “Event construct” then I cast to the game instance (where the widgets are called) and set the appropriate variables to “self” and also a similar thing for widgets called from the player controller.

Never mind it’s not working. The problem seems to be the variables not keeping their values somehow.

Couple questions. 1. How do you know that they are being set correctly the first time? 2. Theres a same state pin for the conteoller reference that doesnt seem to go anywhere, whats up with that? 3. Are you sure that the variable is the correct type?

Also, it would definately help if you showed where the functions are being called. Since its printing not valid that means that the menu variable is null. Are you sure its being set before you do the switc node?

  1. So for this one I took the menu, after creating the menu, the menu is set to a variable “main menu” then I print that variable and it returns menu, then after the play button is clicked, the game instance blueprint opens a level and calls the state transition node which is supposed to remove the previous widget from screen (the remove from parent uses the “main menu” var as ref), it does so successfully but the log returns “accessed none ‘menu’ from ‘transition state’” so to see whats happening I return the value of main menu again once the play level is opened, this returns a null value which to me indicates that the value has been lost, although I’m not sure.
  2. So the same state execution pin is actually unnecessary as, in the function if the state is the same it simply returns an error.

I don’t get this error at any time.

  1. I have set the variable type to the corresponding widget, so that is supposed to be correct.

Here’s an example of a show widget event that I am using to call widgets from other widgets

Now these are always called from widgets that are already created and their variables set to them like this function, the transition state macro is where the switch on enum node is located, so yes the menu variable is set to its widget before it is called.

You said “widgets from other widgets” Is the menu variable another widget blueprint? Or are you trying to refer to Components in the other widget blueprint? Creat widget will make a blueprint, if you want components or variables from them, you need to drag out the bluepin from the create widget node and then get the variable from that blueprint your trying to manipulate.

Also, you showed the custom event you made (cant really read that last one kn my.phone), i need to see where that event is being called

The only thing i can think of is the macro is getting called before that variable is getting set, so its returning null (or will be removed from the viewport). And for some reaons, thats getting returned as being valid after the macro even tho it has no value. Maybe try fetting rid of the is valid after the macro and just create and set it everytime. Im running out of ideas

The event “showPlayMenu” is called from other widgets, thats what I meant by widgets from other widgets, for example it is called from my settings menu’s back button or in a main menu level at event Begin Play then it goes to the transition state variable that removes the previous widget ie. the settings menu from the screen, then checks if the variable “PlayMenu” (widget reference) is valid if not creates and sets the variable to it and add to viewport, if it is just add it to viewport.

Here’s whats happening
-In the main menu, when play is clicked the play menu is created and the playMenu is set to it and it is returned by the string.

then singleplayer is clicked, a level is opened and an in game hud is created and added to viewport, then return the playMenu variable, but then it is null again?

The level changing could be the problem then, ic you didnt already you need to save and load the variables that you need between levels. You do thay in the Gameinstance blueprint

Oh yeah that would solve my problem thanks.