Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
How do I set a WidgetComponent's Widget Class to a Widget Blueprint?
Post Flair (click to view more posts with a particular flair)
Post Body

So I have a Widget Component on my enemies to display a health bar widget, which I made in blueprint. I can set the enemy's widget component to use the health bar widget manually via the editor, but I plan on creating multiple enemy types all using the same base EnemyTemplate code, so ideally it'd be something I set up there rather than manually set it on each child class.

So what I figured I'd do is find the health bart BP file using its text path, then cast what I find to a UWidgetBlueprint. And it works! They find the blueprint, and it even shows up as a variable in the editor.

FString HBarWidgetResource = "/Game/MyStuff/WBP_EnemyHealthBar.WBP_EnemyHealthBar"; //Finds BP
UWidgetBlueprint* GeneratedHealthBarBP = Cast<UWidgetBlueprint>(StaticLoadObject(UObject::StaticClass(), NULL, *HBarWidgetResource)); //Converts to WidgetBP
HudWidgetClass = GeneratedHealthBarBP; //Sets Editor var to what it found

Now the issue is just converting the result of my search, the HudWidgetClass, into something that I can then set my WidgetComponent class to. I figured it'd be just as easy as HealthWidgetComp->SetWidgetClass(HudWidgetClass->GetClass());, but when I compile it, the Widget Class stays blank. If I try casting it HealthWidgetComp->SetWidgetClass(Cast<TSubclassOf<UUserWidget>>(HudWidgetClass->GetClass())); I get an error saying I can't convert from a TSubClassOF<UserWidget> to a pointer of TSubClassOf<UserWidget>.

Any suggestions as to what I might be doing wrong?

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,892
Link Karma
5,366
Comment Karma
4,452
Profile updated: 2 days ago
Posts updated: 5 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 months ago