Hello, I am using user widgets to make health bars for units in my RTS game. When I did so, they all had shadows. I disliked this and attempted to remove them. I changed blend mode to “transparent” and this removed the shadow; however, when the unit moves, the corner of the health bar, a rectangle, begins to disappear/fade/clip/blend weirdly, making the health bar resemble a trapezoid on one side, making a worse visual effect than the shadow the change fixed. This stops when the unit stops moving. Is there another way to remove the shadow? If not, what can be done to stop the warping that occurs?
Can you explain how you have deployed widget, have you added to viewport from blueprint or have attached to character. Sharing a pic might give broader idea for others to reply.
It is attached to the character. I also have the “Space” setting set to world (as opposed to screen.)
Does anyone have a solution? Surely I am not the first person to make a health bar in world without shadows.
For a quick fix you should be able to set the material in your widget to Widget3DPassThrough. This is an engine material which is the base for a family of related material instances. The default one assigned to widget components is Widget3DPassThrough_Masked_OneSided, which uses the masked blend mode instead of translucent like the base does. This causes it to cast shadows. It may be wise to copy the base Widget3DPassThrough material into your content folder, or at least make your own instance of it to use with your health bars. There are slight performance implications of using translucent blending instead of masked, but that’s a bridge you can cross if/when you come to it.
If you’re comfortable with c++, you can try setting CastShadow
to false on your UWidgetComponent
from some c++ code. This class inherits from UMeshComponent
and UPrimitiveComponent
which is where CastShadow
lives. You can’t set this checkbox on your widget component in the details panel because the Lighting category is hidden in UWidgetComponent
:
UCLASS(Blueprintable, ClassGroup="UserInterface", hidecategories=(Object,Activation,"Components|Activation",Sockets,Base,Lighting,LOD,Mesh), editinlinenew, meta=(BlueprintSpawnableComponent) )
class UMG_API UWidgetComponent : public UMeshComponent
Good luck!
-Miso
For those who aren’t comfortable with C++, here’s a static function that can be called from blueprint that does what Miso is talking about:
Required include:
#include "Components/WidgetComponent.h"
The function:
//This function is used to set CastShadow on any primitive component, including UMeshComponent and UWidgetComponent
UFUNCTION(BlueprintCallable, Category = "Lighting")
static void SetPrimitiveCastShadow(UPrimitiveComponent* Primitive, bool CastShadow)
{
Primitive->SetCastShadow(CastShadow);
}
Thank you both for the help. Changing the material while having blend mode set to “masked” removed shadows and reduced “clipping” of the health bar (user widget). I did not test out the C++ because I happened to play with some settings and found that setting “Space” to “Screen” still allows the user widget to move in relation to the world and removed it from any interaction with the lighting, giving a sharper appearance and removing inconveniences dealing with having the widget in the world. I, likely due to my time developing in Construct 3, believed setting “Space” to “Screen” would result in the widget not moving with the unit hence my setting of “World” and why I was dealing with lighting.