Combining C++ HUD with UserWidgets (UMG)
I'm posting this after quite a few days of research, and everything led me into a dead end.
(Have you ever had the feeling that, while you're trying to keep as much as possible in C++, everything you find documented is related to Blueprints? :( )
Okay, so, I'm trying to create a simple HUD Display that combines both a class extended from AHUD (The example FPS one with just the crosshair is fine) with an UMG class created in the editor (I want health amount display, but I'm fine with a text string for now).
My latest attempt was to find the UMG reference in the HUD constructor:
And try to spawn it using CreateWidget() - but it would need a bunch of hacks to get the PlayerController from inside the HUD. (As, a quick reminder, is being setup in GameMode using
It feels I'm missing something stupid, but I'm probably tired of an endless loop search here so I decided to ask you guys if you can help me with this issue.
Of course, recommendations of the best way to set the HUD (using C++) is welcome! Also, I'd like to avoid ditching my custom AHUD class completely (but tell me to do anyway if keeping it is a bad idea)
Thank you guys in advance!
asked Mar 23 '15 at 07:35 PM in C++ Programming
I wrestled with this myself. I was able to get a UMG UserWidget (a blueprint widget) up and running from a C++ HUD in the first person shooter example project:
It seems my original assumptions were very wrong. The way I found is:
1) In Editor, create a UserWidget with the data you want to show on your HUD.
2) In Editor, create a Blueprint based on AMyHUD (your custom HUD on C++ - you can use the provided one in the UE4 template)
3) Edit your HUD Blueprint and on EvenBeginPlay, add a constructor node ("create widget" node) that creates your new Widget (the one from step 1)
4) Set the constructor (create) node return value to "Add to Viewport".
5) On your MyGameMode.cpp, on the constructor, replace the C++ code
And you're done!
Hope this helps someone out there :)
Follow this question
Once you sign in you will be able to subscribe for any updates here