Cast to User Interface

How would I cast to a user interface, I get the casting, but I don’t know what to set the owner to! What should I do? Thanks!

No offense but are you absolutely sure you understand casting?

A cast shouldn’t have anything to do with any owner and generally if you use UMG there should be very few cases where you need to cast the interface. Even with a HUD class there shouldn’t be a lot of cases where you need to know exactly what type it is. The communication usually is extracted from the logic by the UI and not pushed by the logic to the UI.

I’m probably just lacking some context. Could you elaborate on what exactly you are trying to do and what exactly isn’t working? :slight_smile:

You probably try to get a reference of a widget. If that is the case, right after creating the widget, promote it to a variable so you can get a reference from this widget, you don’t need to cast.

you really need to explain what your trying to do here. are you trying to get the players hud or just a random widget? or maybe their camera view? user interface doesnt really tell us anything specifically.

casting basically is a way to identify the class of a object. its like asking is this thing (object in) like the class im casting to. so the object in will need to be a reference to the object your identifying. so if your trying to cast to a healthbar widget then you will need to have the object in be a widget. if your trying to cast to a hud subclass then the input should be a hud. in reality its all about inheritance and asking does the object inherit from this class.

also when you ask a question be very clear, provide details, and when its about a certain node include a picture or a link to the node in the docs. that way we know what your trying to do and which nodes your trying to use.

I understand casting, but I don’t understand what to put for the objet area in the cast node

What I have trouble about casting, is what to connect to the owner.

I am trying to cast just to a widget

I am trying to get a reference to a user interface not a hud, just a user interface. I tried to cast it but i don’t know what to connect it to the object pin.

What reference do you attempt to cast from and what doesn’t work?

That’s because a cast can not be used to gain a reference. It transforms a reference from a child or parent class into the desired one.

This is exactly what I meant when I speculated that you may misunderstand how casting works. A cast does not help you in this scenario. You can not pull a reference from thin air.

Now that we have established that, may I ask what exactly you have and what exactly you are trying to do? Because I’m certain it is possible somehow but I’d have to guess a lot of side factors that would make any suggestions I might provide wrong, almost guaranteed.

I am trying to get a reference to a float variable from the widget to blueprint class. How may I do this?

you need a reference to the widget. where are you creating the widget? where the widget is created is the easiest place to get a reference to it. also what is the context of what your trying to do? there may be a better method to handle what your attempting.

the situation of passing a float from a widget… the only situation i can think of where that would be needed is for player input via a text box or button press. if thats the case you could always have the widget reference the player to pass the information.

So, I am trying to get a variable value from the user interface widget, to a blueprint class. What should I do here?

But there are two blueprint classes. What should I do then?

look i dont want to be a jerk but you gotta work with us here. your responses provide little information to work with, you repeat yourself, and you dont respond to the information / questions posed. we understand you want to get a variable from the widget and pass it to another actor, you said the same thing two hours ago. to get the variable you want you need a reference to the widget. now if i knew where the widget was created and what actor your attempting to pass the variable to then maybe i could give a more specific answer. lets say for example your doing a healthbar widget and your creating the widget in the character, now later you need to reference that widget, thats easy to get since you have access to where its created (the return value of a create widget node provides a reference to the widget created). if the widget is created in another actor though it becomes a much more difficult proposition.

with scripting the devils in the details as they say, one small difference can result in wildly different results. you have provided no details.

Edit: i just reviewed some of the other questions you posted and many lack details or any kind of effort on your part. you also ask a ton of questions on a variety of topics. im guessing your relatively new to all this and many people are glad to help but you cant expect people to do all the work for you either

i would propose another method for what your attempting to do, instead of having the score stored in the widget i would store it in the game mode. the game mode can easily be referenced by the widget and by wherever you are adding score from.

heres how you do it.

first as seen in capture1, open your game mode bp, create a variable for score (playerscore in example), then create a custom event which we will use for adding score. in the example i added a input parameter to the event so we can pass through how much score to add. the script here is pretty basic we take the incoming score and add it to the player score then set the value of the player score. then we check to see if the player score is above the threshold to win the game, score → greater than → branch.

now on to the fruit bp (capture). here we just have an event begin overlap which checks if the overlapping actor is the player and if it is then we get the game mode and call the add score event. as you can see here we get a reference to the game mode then we cast to identify it as the fruitGM class before we can access the values it contains. i also created a score worth variable here so each fruit can have a different value if you wish.

the last section and picture capture2 is the widget. here we simply create the text component then with the component selected go to the content section in the details panel. here look for where it says text and click bind then create binding. the picture below is the binding. for the binding we again get the game mode and cast to identify it, then we get the player score, convert it to text and plug it into the return node.

I would recommend setting that variable in the blueprint class. Then have the interface widget read the blueprint’s variable instead.

So the variable is a score keeper. There are fruits and every time you collect them, they give you different amounts of points depending on each fruit. So when I collect a fruit, I am adding a certain number of points to the score variable. The score variable is located in the user interface widget which are static meshes actor. Then from there, the score variable gets updated and gets shown on the screen. I’m also looking to see if the variable is over 100 and beats a high score in another user interface widget.

Set the variable on both at the same time.

how the above functions is when the player overlaps the fruit actor that actor contacts the game mode and calls the event to add score. the widget basically just waits around listening for any change to the score variable in the game mode and updates automatically so no need to reference the widget.