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"

How to cast a variable from HUD to a ThirdPlayerCharacter?

Hello, how can i cast a variable from HUD to a ThirdPlayerCharacter ?

I'm inside the ThirdPlayerCharacter and i created this: alt text

I'm trying to do this: https://youtu.be/YOkoyp8Mn6s?t=23s

Product Version: UE 4.19
Tags:
unbenannt.png (88.2 kB)
more ▼

asked May 27 '18 at 03:36 PM in Blueprint Scripting

avatar image

G1K777
36 3 4 13

avatar image TheParadox May 27 '18 at 07:17 PM

Okay - fine, maybe I do not understand what you are trying to do... So the next question IS: why do you need to access the HUD?

I guess I am wondering why would would not simply use "Get Mouse Position"

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

3 answers: sort voted first

Hello!

Just get hud from player controller and cast to your special hud.

You cannot cast a player to a different thing !

Also, it's always good to upvote people who have helped you, you'll have more chances to get help in the future ;)

and make sure your special hud is selected inside the game mode

more ▼

answered May 27 '18 at 04:56 PM

avatar image

AZTECCO
1k 17 8 15

avatar image Nebula Games Inc May 27 '18 at 05:01 PM

Yep, this works...do this haha

avatar image G1K777 May 27 '18 at 06:58 PM

The thing is, i have a hud and i want to pass the "HUD VAR" to my ThirdPersonCharacter. Not T.P.C. -> HUD.

avatar image AZTECCO May 27 '18 at 07:10 PM

Yes I know, as I said drag from get player controller , get hud, and cast it to your custom hud. And you can access it.

avatar image G1K777 May 27 '18 at 07:21 PM

I did a bit different, i open the ThirdPlayerCharacter and did this: alt text It works almost perfect except that "Get Viewport Size" has a resolution of 1280x720 and the Cursor Position has a resolution of 1920x1080. So the Viewport Size is the real Game window resolution right? But why is the cursor giving a higher resolution?

unbenannt1.png (111.9 kB)
avatar image AZTECCO May 27 '18 at 07:32 PM

Maybe there is a difference between your real size and the defaults of your project, probably you have to scale the position accordingly

avatar image TheParadox May 27 '18 at 07:35 PM

I think that has to do with the editor viewport, I believe IF you run it in "New Editor Window" or "Stand Alone Process" it might solve that issue - as running it in the Editor window, the window is only as big as you set it, when the "true" size might be different.

avatar image G1K777 May 27 '18 at 07:41 PM

So the ViewPort is the real window size and yes, i'm using new window the whole time, but when the window is only 1280x720 why is "Get Mouse Position on Viewport" showing me 1920x1080?

avatar image TheParadox May 27 '18 at 07:45 PM

What is your screen resolution (for the monitor)

avatar image TheParadox May 27 '18 at 08:08 PM

Try this - will give you the actual coords inside the screen WITHOUT having to do any math Apparently the function you are currently using WILL work best ONLY in fullscreen.

alt text

mouseposition.png (80.6 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

EDIT: Okay, since people need to insult the intelligence of those trying to help - when the questions are not that clear themselves... First you need to spawn the "Widget" (if not already done) and connect it to the viewport. When you create the "Widget" - it is best to store a reference to it in a variable, that way you can easily communicate with it in the future.

ALSO: when you cast to an object, you need to PASS it an object - the controller CANNOT be casted to a HUD, because it is not a HUD - its a controller.

A simple example of using a "Cast To" node. Raycast -> hits an object, Cast the object to (example) "Third Person Character". IF the cast is successful, then you clicked a "Third Person Character" and can "safely" use functions (or store a reference to it) found in that object, otherwise it is someother object, that we may not care about (and may not have the functions we want to call on a click.)

more ▼

answered May 27 '18 at 05:03 PM

avatar image

TheParadox
10 1 5

avatar image AZTECCO May 27 '18 at 05:34 PM

Hello! Maybe you're talking about widgets or hud elements in general.

Attention, the HUD is inside player controller and it's "declared" inside the game mode settings. You don't need to spawn it. Just to clarify..

avatar image TheParadox May 27 '18 at 07:10 PM

Okay, I have no idea where my comment went... BUT I know HUD's and Widgets are not the same thing - BUT the way he is describing it SOUNDS like a widget.

avatar image AZTECCO May 27 '18 at 07:25 PM

Fine! Sorry but sometimes the HUD is not really clear and right, simply using a user widget created from player controller is the easy and clear way.. I think HUD are more for ue3 users and manual draw , in ue4 we have umg and the use of HUD is not really handy for new users just like me. But I'm using it.. As a manager for umg

avatar image G1K777 May 27 '18 at 06:57 PM

Exacly what i was thinking, widgets are inside a HUD_BP. HUD and Widget aint the same. Widget is a childclass of HUD.

avatar image TheParadox May 27 '18 at 07:10 PM

Yeah, BUT then why are you trying to get the HUD class? why not just create the widget?

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

I recommend doing this. Just save your HUD as a variable when you add it to your viewport. When you need to use a variable from the HUD, just get HUD variable, and get the variable you need from it. alt text

capture.png (123.0 kB)
more ▼

answered May 28 '18 at 03:53 PM

avatar image

FlameOfIgnis
397 5 5 13

(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