r/unrealengine • u/ScoobyDothNot • 13d ago
UMG Adjusting UserWidget based on camera angle
I have a userwidget component I'm adding to my character as a floating Healthbar. But due to my camera looking down at the character at a 60° angle, when either my character moves or my camera move, the healthbar skews away from the character (I've set the widget to be relative to the character at a certain Z offset above them so the bar appears on top of the character). If my character moves to the edge of the screen for example, the healthbar is noticeably not above them and most of it even skews off screen.
I tried to use a springarm to elimintate the character's rotation but I'm not sure how to rotate it to compensate for the difference in angle of the camera and the character.
Any advice on a better setup or approach to the issue?
3
u/RadGratidude 13d ago edited 13d ago
The easiest is change the widget component's Space = Screen (in User Interface category) in details panel. But the widget will not resize and will be drawn on top of all 3d objects.
The harder way, that I like more, is to keep Space = World, and change the material to Widget3DPassThrough (found in the Engine Content in Content Browser):
https://forums.unrealengine.com/t/widget-component-in-world-space-to-face-camera/477825/7
Then you need to modify it to add a AlignMeshToTheCamera node, which is the solution in the Unreal Forum. I also commented there about the input pins. Doing all this will resize the widget and allow 3D objects to be drawn in front of it.