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.
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?
Subreddit
Post Details
- Posted
- 5 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/unrealengin...