Character Health Bars Are Visible Through Walls

If you are making the health bars by creating widgets and adding them to the viewport, then the computer thinks they are “on top” of everything else on the screen. No adjustment of materials in the UI is going to change that. To my knowledge, there is no way to make a widget register as “behind” other objects in a scene.

I guess if you wanted to get really deep with it, you could make a line trace from the player camera to the enemies and have the enemy’s healthbar widget only show in the viewport if the line trace hits the enemy. I’m not sure how to code that off the top of my head, but it seems like it might work.

Detach789 Thanks. I was afraid of that. I’m going to have several bad guys and knowing where they are defeats the purpose.

I have enemies with AI and they wander around until they see the player, then they attack. However, where the enemies are is supposed to be a secret. Right now I can see their health bars through the walls and it’s driving me crazy. The material is UI material, so it does not have the depth option. I can’t seem to find anything in on it.

Use widget components in world space; you may want to rotate them to face the camera, this will give you spot-on occlusion behaviour.

Image from Gyazo

Or, if you wish to use screen space widgets, a visibility trace back to the camera and/or player will do the trick as Detach789 suggested:

It does not need to be a widget component in this case, of course.

2 Likes

Well…that’s embarrassing. :wink: I guess I don’t know enough to try to help people yet then.

Thanks for info about widgets being used as components.

Thanks a million for the blueprint!! I will give it a shot and see what happens. I can always just remove the health bar and the enemy will die when he dies. Or not…

Embarrassing? But your suggestion is spot on.

The blueprint did the job and I mostly understand it! Thanks again!!

No problem!

Thanks for the encouragement!

I should still go try out those fancy widget actor components though. :slight_smile: