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'm currently working on a 2D shooter for a school project, and I am working on the enemies. I've added a widget component to them that displays their health, but whenever they begin moving and chasing after the player the healthbar rotates along with them. So I figured I'd add another empty scene component to them to serve as a sort of "widget root," that would have its rotation set to absolute so it would follow the enemy but not rotate with them, then attach the health bar to that. However, it doesn't work. At least, it doesn't work for the widget. Adding things in after the fact, like a cube via the blueprint editor, works fine, they keep their rotation, but the widget continues to rotate despite sharing the same parent component as the cube. I don't understand what is going wrong, did I set something up incorrectly? What about the cube results in it working properly?
Here's my declaration code for the widget root and the widget.
EDIT: I've managed to get it so the widget does not rotate, but it still moves around, as if the root is still rotating but the widget has absolute rotation, which is not at all what I coded.
WidgetRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Widget Root"));
WidgetRoot->SetupAttachment(GetRootComponent());
WidgetRoot->Mobility = EComponentMobility::Movable;
WidgetRoot->SetAbsolute(false, true, false);
WidgetRoot->SetRelativeRotation(FRotator(0, 0, 0));
//Adds Health Bar
HealthWidgetComp = CreateDefaultSubobject<UWidgetComponent>(TEXT("Health Bar"));
static ConstructorHelpers::FClassFinder<UUserWidget>hudWidgetObj(TEXT("/Game/MyStuff/EnemyHBar_CPP"));
if (hudWidgetObj.Succeeded()) {
HudWidgetClass = hudWidgetObj.Class;
}
else {
HudWidgetClass = nullptr;
}
HealthWidgetComp->SetWidgetClass(HudWidgetClass);
HealthWidgetComp->Mobility = EComponentMobility::Movable;
HealthWidgetComp->SetupAttachment(WidgetRoot);
HealthWidgetComp->SetDrawSize(FVector2D(100, 50));
Subreddit
Post Details
- Posted
- 6 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/unrealengin...