Error creating a UUserWidget in C++
I'm trying to create a widget through C++. Here's my code:
The compiler and IntelliSense don't give me any errors but when I call the SetupInGameUI() function UE4 just crashes and it says in the log "Error CreateWidget can only be used on UUserWidget children"
I have the following includes:
Game.h (project header)
and the following modules in Build.cs
The widget that i'm trying to create is a blueprint widget. I don't know if this is the problem but if it is I just don't know another way to do it.
Thanks in advance!
asked Aug 24 '16 at 11:38 PM in C++ Programming
The issue here is that you are using your GameCharacter to try and handle what the HUD class should be doing.
Starting from where you are now, as you've added the proper header files and modules in the Build.cs file, you'll need to create a class that extends from UUserWidget:
[UGUserWidget.h] (UGUserWidget.cpp is empty but does exist.)
Then, you need to create a HUD class that can load the UGUserWidget class and add it to the player viewport:
Compile, and back in the editor, you'll need to create a UserWidget with the class type of UGUserWidget. So, create a UserWidget as you normally would, ( Right click in Content Browser -> User Interface -> Blueprint Widget) , and name it.
Open the Blueprint Widget and on the top right, click "Graph".
Then, on the left side of the top bar, click "Class Settings".
Now, on the bottom left Details panel, change Parent Class from User Widget to GUser Widget.
Make sure your GameMode class is loading the HUD class:
Back in the editor, add some text to your Blueprint Widget and make sure your maps Game Mode is set to your game mode that is loading the HUD Class and then Play In Editor.
You should see the text on the screen.
answered Aug 25 '16 at 02:33 PM
ImVawx ♦♦ STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here