Hello,
This question has been asked a million times, and I’m still searching through all the different answers, but I’ll post my specific case here and hope that someone drops me a tailored hint:
I have an interactable actor in the level. When you press a button near it, text appears in a UI widget on the screen, and that text varies depending on an integer variable set in the object. So the same blueprint can be duplicated throughout the level, and depending on the integer variable each is set to, a different text will appear in the UI.
I am very close to completing this system, but I can’t get the UI blueprint to read the integer variable in the actor. How do I get the variable in the UI blueprint to read the actor blueprint variable and match itself to it? Here are some screenshots of the widget BP and interactable actor’s essential code:
you need a refernce to the actor to be able to get the data from it.
from what i can see, all you need to do is set both interaction text and index to be instance editable and to be exposed on spawn. this will make them appear as imputable values on the construct Widget node.
also, a quick tip; turn that newly created widget into a variable. that way you can explicitly reference it later for removal.
your current code would remove every widget from screen when an overlap occurred, even the ones you dont want to be removed.
i was considering writing that, but that has tripped me up in the past. for general purpose getting and setting references in other objects, thats the way to go, but for spawn you may want to set it at spawn time.
the thing in the past that tripped me up was that i did what you did there, but it caused me to grab null values inside the actor as there was a frame tick between the spawning of the actor and the setting of the values. not sure if this was a bug, or just the way unreal engine handles actor spawning but it would happen randomly, and i eventually fixed it by setting a delay (then setting it to be expose on spawn once i realized how that worked) from that point on.
basically, setting it to be exposed on spawn like that means ill know for sure, regardless of any threading weirdness or the tick timing, that the data will be inside the object as expected.
Thank you for getting back to me so quickly! The ‘remove from parent’ optimization worked like a charm. I also checked the boxes you showed me for the variables.
As for reading the variable, I tried passing the variable from the interactable actor through a blueprint interface (the function has only inputs). Then, I call the blueprint interface function as an event in the target blueprint, and read the variable from the outputs there.
I apologize- I didn’t realize at the time that the character blueprint was defining the variable that the widget was initiating with. When the widget was created on screen, the character BP was defining the value of the variable in the widget blueprint. SO, I made the interactables use the BPI function to record its variable, then I called the event when that function fired to feed the variable into the character BP, then the character BP took that variable and defined the value of the variable in the widget when it creates it.
Interactable actor > Interface > Character BP > Widget
That’s roughly how I understand this setup to flow. In the end, my widget, actor, and character BPs look like this: