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:

I’m trying to do this:

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 :wink:

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

1 Like

Yep, this works…do this haha

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.)

1 Like

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…

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.

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.

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

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”

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

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

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

The thing is, i have a hud and i want to pass the “HUD VAR” to my ThirdPersonCharacter. Not T.P.C. → HUD.

I did a bit different, i open the ThirdPlayerCharacter and did this:

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?

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?

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.

What is your screen resolution (for the monitor)

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.

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.

Hello!

Take a look… maybe this can help you!