Hello guys, this is my first post here, i hope you can help me
I have a simple question. I have a widget called BPI_W_CONTADOR TOTAL and, inside of it, i have a float variable called “Precio Final Total” which its value changes during the game (it is a price). That value is set in the respective widget and everything works fine when i want to see it in the screen directly from that widget (adding it to the viewport).
The problem comes when i want to take that variable from my Level Blueprint and do something with it (what i want to do with it is not the key of the question) because, when i take that variable, it seems like its not updated. The value that it shows me is 0.0 instead of the new values that have been set when i play
I tried different approaches to call that variable in my level blueprint, like creating references of the widget in my BP_CHARACTER that, later, is calling using a “cast to”, a “get all actors of class”, or even directly creating my widget and calling that variable.
But none of them worked (i insist, the variable is properly taken but not with the value that has been set during the game).
I would apreciate very much if some of you could help me, its very frustrating and i know this has to be very easy to do. Thank you guys!!
I believe the event construct of a widget fires upon being added to the viewport. Are you perhaps trying to get the value of this variable before the widget has ever been put on the viewport?
I replicated what you tried to do, and for me it works perfectly.
Given what you show, you try to get the variable on creation of your widget. This will always give you the default value (which is by default 0,0) since it is constructed at that time.
You also try to get the variable through your BP_Character, the problem will probably lie there.
Example of how I replicated what you tried to achieve:
I created a widget, with a variable MyWidgetFloat, and added delta time to it on event tick.
In my level blueprint on begin play I create the widget and add it to my viewport.
I get the variable in 2 possible ways.
1: by using a variable I set on creation of my widget, and getting the variable from there.
2: by using get all widgets of class, getting the first one (since there’s only one) and getting the value.
And here the result in my game. (i also added the value to my widget, so you see they both go up)
Here is what i did:
I created a new widget with the variable Float_Test (by default with a value of 2). Then, I set this new variable adding +10.
In my level blueprint, i created a reference of the widget and i took the variable from it, but instead of returning me a value of 12 (2+10) it still gives me 2…i dont understand!
Please, i need help with this…
Tick will not be called if you don’t add your widget to the viewport.
i think im stupid…I cant believe this was the reason…now i understand what a event tick does. Thank you very much guys!!! i really apreciate it!!