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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Get Blueprint class from C++

The only problem I have is retrieving the Blueprint Widget class using C++. I can't seem to get it.

header:

 TSubclassOf<class UUserWidget> GUI_PlayerEye_Class;
 UUserWidget* GUI_PlayerEye;

cpp:

 // in PostInitializeComponents
 static ConstructorHelpers::FClassFinder <UBlueprint> playerEyeGUI(TEXT("/Game/UI/BP_PlayerEye_GUI")); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ERROR HERE
 GUI_PlayerEye_Class = (UClass*)playerEyeGUI.Class;
 if (GUI_PlayerEye_Class == nullptr) { LOG_ERROR_SAFELY("GUI_PlayerEye_Class is NULL.") }

 // in BeginPlay
 GUI_PlayerEye = CreateWidget<UUserWidget>(this, GUI_PlayerEye_Class);
 if (AddToViewport) { GUI_PlayerEye->AddToViewport(); }

It compiles but when running the game: Error in ConstructorHelpers.h on line 157: UE4Editor.exe has triggered a breakpoint.

I tried this instead but it generated more or less the same error:

 static ConstructorHelpers::FObjectFinder<UBlueprint> playerEyeGUIObj(TEXT("/Game/UI/BP_PlayerEye_GUI")); // <<<<<<<<< ERROR HERE
 if (playerEyeGUIObj.Succeeded())
 {
     GUI_PlayerEye_Class = (UClass*)playerEyeGUIObj.Object->GeneratedClass;
 }

Product Version: UE 4.18
Tags:
more ▼

asked Nov 17 '17 at 07:48 AM in C++ Programming

avatar image

Napoleonite
590 89 104 153

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

1 answer: sort voted first

Hey!

First of all: Constructhelper's works only if you call them from the constructor itself. Second: you should use fclassfinder but spawn normal uuserwidget then set his class. Here is a link maybe help: https://answers.unrealengine.com/questions/546442/c-reference-to-widget-component-without-editor.html

Third (and this is my suggestion): You can do transparrnt widget classes instead of hardcode everything in constructor. What i mean?

Inherit new widget class from uuserwidget. Add tsubclassof widgetclass in your class.. Make it blueprint editable. Create a new widget in editor. Set your widget class as parent class in class default settings.. from this point you can setup yourwidgetclass variable in editor.

You can freely edit your widget anytime, you will have c++ access for your widget, you can implement any functions into your widget... but design and everything else can be done in widget editor :)

Of course for your class you need use Blueprintclass to edit your widgetclass variable, but that should be not problem unless you do full pure c++ development...

Cheers

more ▼

answered Nov 17 '17 at 10:01 AM

avatar image

AmphDev
1.5k 15 9 33

(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