GET from HUD to another Blueprint?

Hi there,

I make a very simple Idle game and I store all stats in the HUD blueprint. (I know it’s not ideal but so far it works nicely for me.) I would like to create a clickable button and use it to Set a float value in my HUD blueprint on click.

  1. Is it possible to make a button like that in the HUD? If so, how?
  2. If it is not possible, and (for example) I have to put the button on the map, how can I access the float values in the HUD to Get and Set them?

Thanks guys, any help is appreciated :slight_smile:

There is a node in the HUD class to create a button, have a look at the content examples HUD map, which features some buttons.

With a button you mean a 3D object in the map or a 2D one that is on your screen all the time?
First one is a blueprint with a Buttonmesh of class Actor.
Now if you press E or something, you can make a line trace and check for the buttons collision type. If you hit him, you break the hitresult and cast the hit actor to your ButtonBlueprint. Now you could access your HUD from the PlayerController and cast it to your HUD class.
You could change the values on your Character BP now or you get the HUD inside the Button BP and not in the CharacterBP to let multiple Buttons change different values. You would need to create a function inside the Button BP and there you change the value and get thr HUD Class from the controller. Remember to cast the HUD to your HUD class. Now on your Character BP you can call the function from the returnvalue of the Cast node that casts the hitactor to your button.

You have a few options on how to create a button in the HUD, and you do this all in the HUD blueprint:

1.First method is to draw a texture in wanted position and then create a HitBox in location you want to detect clicks.Look at the screenshot 1. You have to name the hitbox, and then set up a “receive hitbox event” something like in screeshot 2, the switch loop checks for name of the hitbox that was clicked.

more info: Create a simple menu like in the Strategy Game - Programming & Scripting - Unreal Engine Forums

2.Other method would be to use StaticMesh component inside of a blueprint, and add click events to it, this could be in HUD or other blueprint, but remember you will need to cast it to your HUD blueprint if you do that.

more info: How to detect object on mouse click - Programming & Scripting - Unreal Engine Forums

3.There are also buttons you can create, this function creates a simple looking button with text, but I haven’t used that yet , partly cause my HUD is all made from textures I made , and those buttons don’t fit in visually.

The game supposed to look something like this in the end:

The button is like a menu button, so I guess it is 2D. I used the New Project: Blueprint Puzzle for the basics, so I have fixed camera over a 3D environment, which makes it pretty much 2D. On leftclick, I would like to change a float value which is located in the HUD. I was able to add a button to the Example_Map as a mesh, and I can add the click event, but when I have to access and modify the float values in the HUD, I’m stuck.

Hi Jurif,

I tried the first version, drawing texture HUD but for some reason I cannot see the texture when I hit play. Any ideas?

ok, figured it out in the morning :slight_smile: I choose to go with the texture/hitbox combo, imho it works best for simple 2D games like mine. big thanks Jurif, it really works!