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.
Is it possible to make a button like that in the HUD? If so, how?
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?
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.
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.
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.
ok, figured it out in the morning 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!