How to set widget using ConstructorHelpers?

Currently I am using:

`static ConstructorHelpers::FClassFinder<UUserWidget> WidgetContainer(TEXT("/Game/Widgets/LockOnIndicator.LockOnIndicator"));
	if (WidgetContainer.Succeeded())
	{
		WidgetComponent->SetWidget(Cast<UUserWidget>(WidgetContainer.Class))
	}`

But the WidgetContainer fails to succeed. Any solutions?
Thanks in advance.

	static ConstructorHelpers::FClassFinder<UUserWidget>WidgetContainer(TEXT("WidgetBlueprint'/Game/Widgets/LockOnIndicator.LockOnIndicator_C'"));
	UClass* WidgetClass = WidgetContainer.Class;
	
	if (WidgetContainer.Succeeded()) {
		WidgetComponent->SetWidgetClass(WidgetClass);
	}

I’ve tried that but it still fails to succeed.

Is your LockOnIndicator widget a blueprint widget or is it a 100% c++? (UMG with parts of slate)
I get success with a bp version.

Blueprint.

Are you calling


	static ConstructorHelpers::FClassFinder<UUserWidget>WidgetContainer(TEXT("WidgetBlueprint'/Game/Widgets/LockOnIndicator.LockOnIndicator_C'"));
	UClass* WidgetClass = WidgetContainer.Class;
	
	if (WidgetContainer.Succeeded()) {
		WidgetComponent->SetWidgetClass(WidgetClass);
	}

inside of the CDO?

Yes.

WidgetC3.zip (92.8 KB)

Here is a scene where it is implemented & working. You must be making an error somewhere else in your project.

The code is inside of MyCharacter.cpp
Duplicated your widget path so it should match.

Run it with debug enabled and you will see that it goes into the .succeed area and sets the widget correctly from class.

Doesn’t work for me.

You must be doing something wrong in your code elsewhere. Here is proof it works

I trust you that it works and I’ve tested it but in my code it doesn’t succeed for some reason and I don’t know why. It says it fails to find /Game/Widgets/LockOnIndicator.LockOnIndicator

Because you need to add a “_C” at the end.

	static ConstructorHelpers::FClassFinder<UUserWidget>WidgetContainer(TEXT("WidgetBlueprint'/Game/Widgets/LockOnIndicator.LockOnIndicator_C'"));

You are calling a blueprint not the c++ class so you need to add a suffix _C to the object type (second name after the dot)

Still doesn’t work.:frowning:

is your path to the widget correct? Do you have any non-Latin letters in your asset path that might be causing problems for unreal?
Try fixing redirects on the directory with your widget.

At this point there’s not much I can help you with.

I copied the reference path provided by the engine so it should be correct. Again I appreciate all the help you’ve been over the past few days. Tysm. And sry for the back and forth hassle.

This is the path unreal engine gives /Script/UMGEditor.WidgetBlueprint’/Game/Widgets/LockOnIndicator.LockOnIndicator’

The reference link doesn’t really work with this type of loading

This is the reference unreal generates

/Script/UMGEditor.WidgetBlueprint'/Game/Widgets/LockOnIndicator.LockOnIndicator'

this is the path that works, you also show unreal the class of object

TEXT("WidgetBlueprint'/Game/Widgets/LockOnIndicator.LockOnIndicator_C'")

I know and I’ve tried both ways but for some reason both don’t work.

I don’t know why this doesn’t work but my animation blueprint does.

Can you post the snipped ot code you are using & show folder structure where the widget is in?