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"

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

  1. Create full HUD on UMG Editor (Done, this is easy);

  2. Reference this HUD on a C++ class (???);

  3. Show HUD on the screen (???);

  4. Access any element in it, change the texts, values, bars, etc! This would be heaven!

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

Product Version: UE 4.12
Tags:
more ▼

asked Jul 25 '16 at 01:51 AM in C++ Programming

avatar image

pfjarschel
3 1 2

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

1 answer: sort voted first

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!

more ▼

answered Jul 25 '16 at 09:58 AM

avatar image

braindigitalis
163 7 10 13

avatar image Atheist91 Jul 25 '16 at 10:41 AM

More suitable for health/energy/ammo would be class deriving from APlayerState.

avatar image braindigitalis Jul 25 '16 at 10:44 AM

Yes this is true. APlayerState is managed on a per-player basis, whilst GameState is global to everything, overarching the player state. Both can and should be used for this depending upon what you want to store.

avatar image pfjarschel Jul 25 '16 at 12:12 PM

Thank you so much! After a good night's sleep and reading your suggestion, it makes so much sense that I feel so dumb right now... I even started trying to implement a Slate UI, but that's not simple at all! I'll try what you suggested and see what happens!!

avatar image pfjarschel Jul 25 '16 at 03:32 PM

Just to give anyone who's having the same problem a simple step-by-step to what I did:

  1. Create HUD on the UMG Editor;

  2. Create a custom GameState class;

  3. Set that GameState class as the one to be used, in the GameMode.cpp (remember to include your custom gamestate.h!):

    GameStateClass = APacGameState::StaticClass();

  4. Do stuff on your code, reference and set values to the game state. This is how I referenced it (not sure if you need all that, but it ensures nothing is null):

    APacGameState* gameState = GetWorld() != NULL ? GetWorld()->GetGameState() : NULL;

  5. Create a new blueprint (yeah, there's no escaping those) to exclusively call your HUD, and place it on your level (and set it hidden in game). This is how I did it:

alt text

  1. Create bindings to the values you want to change on your hud. An example:

alt text

That's it! It worked beautifully for me! And I have to admit, after taking a small time to actually learn a little about bluprints... Well, they're kind of sexy, can't say I still hate them!

Thank you so much braindigitalis!

showhud.png (107.6 kB)
binding.png (114.8 kB)
(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