x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.20
Tags:
more ▼

asked Nov 17 '18 at 03:41 AM in Blueprint Scripting

avatar image

CODE REDBALLG
115 3 7 17

avatar image Erasio Nov 17 '18 at 10:05 AM

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? :)

avatar image CODE REDBALLG Nov 17 '18 at 06:47 PM

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

avatar image ThompsonN13 Nov 17 '18 at 07:05 PM

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.

alt text

capture.png (53.5 kB)
avatar image CODE REDBALLG Nov 17 '18 at 10:57 PM

I am trying to cast just to a widget

avatar image Erasio Nov 17 '18 at 11:18 PM

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

avatar image CODE REDBALLG Nov 17 '18 at 11:28 PM

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.

avatar image Erasio Nov 17 '18 at 11:34 PM

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.

avatar image CODE REDBALLG Nov 18 '18 at 12:39 AM

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

avatar image ThompsonN13 Nov 18 '18 at 02:55 AM

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.

avatar image CODE REDBALLG Nov 18 '18 at 03:03 AM

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

avatar image Debaucher Nov 18 '18 at 03:14 AM

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

avatar image CODE REDBALLG Nov 18 '18 at 03:20 AM

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

avatar image Debaucher Nov 18 '18 at 04:17 AM

Set the variable on both at the same time.

avatar image ThompsonN13 Nov 18 '18 at 03:20 AM

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

avatar image CODE REDBALLG Nov 18 '18 at 03:38 AM

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.

avatar image ThompsonN13 Nov 18 '18 at 04:07 AM

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.

alt text

alt text

alt text

capture1.png (88.2 kB)
capture.png (109.3 kB)
capture2.png (80.5 kB)
avatar image ThompsonN13 Nov 18 '18 at 04:09 AM

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.

avatar image ThompsonN13 Nov 18 '18 at 04:16 AM

now if you are dead set on your current method then the below is a simple example of how it can be done. you create the score widget then save a refernce of it to a variable. then you have a overlap event either on the character or in the fruit bp and you get that widget reference. its simple here since its all in the same bp but if you were trying to do this from the fruit bp then you would first need to reference the player character and cast to the needed class before you could get the widget reference.

alt text

capture.png (165.5 kB)
avatar image CODE REDBALLG Nov 18 '18 at 05:02 AM

Ok Thank you so much for your help!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Nov 17 '18 at 10:18 AM

avatar image

Ego Studio
606 4 4 5

avatar image CODE REDBALLG Nov 17 '18 at 06:47 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question