Losing my mind: UMG, HUDs, etc, from c++ code
Ok, I spent the whole day trying to figure this out, and I have finally given up. If I wasn't required to do this project on Unreal, I would have gotten back to Unity already. I don't mean to sound rude, but man...
Anyway, my question is really simple: How do I display a small text on the screen? Shouldn't be too hard, but I read tons of pages of tutorials, and so far, nothing. I would think the HUD I created with the UMG editor could do the job, but how do I get it to show on the screen (from c++ code, of course)?
How I think it should be (seems the most direct and obvious way):
If someone could point me to the right direction on figuring this items out, I would really appreciate it!
If there is no way, and I simply HAVE to use blueprints, how do I do to make the hud blueprint access a variable on a c++ class? For example, I have a "coins" property stored on a pawn class. If I want the Text block I created to access this property, how do I do? Because I followed the "Creating Health/Energy and Ammo indicators" tutorial, but there isn't anything I can bind it to! And still, how would I do to show the hud? Because so far, I haven't even been able to do this... :'(
Additional info: I'm using custom pawn/actor classes.
Thank you all in advance, and whoever is able to help me with this deserve a beer! And sorry if my text is confusing, I haven't been sleeping much...
asked Jul 25 '16 at 01:51 AM in C++ Programming
Personally i would store all the values to be displayed in my HUD in the GameState class.
Create a C++ GameState derived class in your project, put all of your HUD-accessible values there such as health, energy, ammo etc.
Then, modify those as you wish in C++, make sure they have the correct UPROPERTY() definition so they're blueprint accessible (to be honest, BlueprintReadonly should be more than enough) then use the tick and update etc methods of the HUD blueprint to draw your HUD based upon the properties from the gamestate.
If you later find you can't do something you want, simply add more GameState so you can.
GameState is great for this as it is accessible everywhere in the game, blueprint, C++ or otherwise. You can even hook delegates to it and use it for messaging.
Hope this helps!
answered Jul 25 '16 at 09:58 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here