Let me get your logic right. So you have an external widget class WidgetBPContainer that you are setting inside of the editor.
You must understand that when you use TSubclassOf you are telling unreal
“I’m setting this variable as an instance of User Widget in the editor”
It only holds the class of the passed in widget in this case.
The line
WidgetBPContainer = WidgetContainer.Class;
Doesn’t really make sense. You are setting a class to another class.
You can only use WidgetBPContainer (a UClass) to create a widget from it. It can’t be used as a widget instance on it’s own.
You create the widget component LockedOnWidget in the constructor and that is where you want to call LockedOnWidget->SetWidgetClass(WidgetContainer.Class);
if you want the full reference to the widget then you should be using
UUserWidget* WidgetBPContainer;
That would give you a full object of type User widget.
If you are still having problems then PM me the project and I can fix it for you. It still seems rather small so it shouldn’t be a problem to upload to the cloud somewhere.
Ty that clears up a lot but it still fails to succeed when I do it that way. Also WidgetBPContainer is just used to store the Widget Blueprint given by ConstructorHelpers which I use to set the Widget Class in a function.
If it’s not working then it’s a matter of moving assets to folders in unreal. Try going on all directories and right click “Fix up redirectors” and look into your file explorer that the widget is physically in the right place
has no impact on if the widget shows up or not. It’s not used anywhere besides it being set in the constructor. It doesn’t take part in the process of showing the widget. There is no need to focus on it at the moment.
Make sure none of your header or cpp files are in intermediate by accident (vs can sometimes save there). All of your c++ code should be in you “Source” directory
Select temp folders
Right click uproject file and Generate.
Project should be rebuild
double click project file as normal. Build & run from IDE
Ok so I’ve managed to make it work but I don’t know why. I just loaded it up, replaced a few things and it just decided to work for some reason. Here’s the solution but it’s a solution I’ve tried in the past so I don’t know why it works now.
TargetDummy.h
TSubclassOf<UUserWidget> WidgetBPContainer;
TargetDummy.cpp(Constructor):
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetContainer(TEXT("WidgetBlueprint'/Game/TargetDummyWidgets/LockOnIndicatorWidgetBP.LockOnIndicatorWidgetBP_C'"));
if (WidgetContainer.Succeeded())
{
WidgetBPContainer = WidgetContainer.Class;
}
I used TSubclassOf instead of UUserWidget* as in the cpp file there’s no suitable conversion function to convert from UUserWidget* to TSubclassOf could anyone explain this to me?
Again thanks to @3dRaven for all the help and support, you helped tons and I am forever grateful, you’re amazing!