Selectively Occluding an Actor/Widget

Newbie here,

I’ve been trying to get a handle on UE4 by working on a Star Fox/Panzer Dragoon styled rail shooter, where the player pretty much controls a cursor to aim attacks and slightly reposition the player’s pawn.

Anyways, I seem to have hit a snag on getting said cursor to behave as I would like. I’m trying to make it render over everything on the screen EXCEPT the player’s pawn, and I currently haven’t found a way to do so.

I’ve tried working with the cursor as a UMG HUD element, which obviously renders it over the background elements properly, but I haven’t figured out a way to occlude a HUD by a given object. I’ve also tried placing cursor as a mesh object/3d widget that is parented to the camera, which properly occludes the cursor via the Player Pawn, but it also makes the cursor occluded by everything else in the world as well, unless I disable Depth Test, which goes back to the earlier problem of it indiscriminately disabling occlusion.

Anyone know of a way to get this effect somehow, as it’s the one effect I consider an absolute requirement for this style of game?

This tutorial is what you’re looking for instead of the player pawn’s location, you are going to want to get your mouse/cursor’s screen location as a world position (or your target, depending on your intended functionality), and use that instead

Let me know if you need any additional behaviour or if you get stuck
And I’m new here so I appreciate any +1s :slight_smile:

Thanks for the link; It’s definitely has got me onto the right track.

Setting up the cursor materials with an opacity mask set by the pawn’s location in screen space seems like the way to go. Only thing I need now is a way to generate the mask from the pawn’s silhouette in screen space, rather than using just an indiscriminate sphere mask. Is there some mobile-friendly way to generate a mask from this silhouette without resorting to rendering it out into a custom depth buffer?

I don’t quite follow you.
You don’t need any mask from the silhouette of your player.

The material that your player pawn uses, is set up how it is in the video: to allow a sphere mask, based on where your cursor is, to create an opacity mask over the player mesh.
Render custom depth doesn’t get involved here at all.

Rather than using, a sphere mask, I wanted to make the mask for the cursor from a projection of the Pawn’s Mesh to get exact mask boundaries rather than constantly tweaking the the radius for each type of pawn I’d end up creating. Anyways, I’ve managed to get it working by rendering the mesh into the stencil buffer, and it works exactly as I want it to, but I’d like to find a way to what I need without a custom depth buffer so it’d work on a mobile target.


Anyways though, thanks for the help. I can finally get working on actual game logic instead of spending more hours waging a war against my OCD in the Material editor

You could combine a few (for example, 3) smaller sphere masks and combine them into the same effect. This would give you a much tighter mask on your mesh, you could get it pretty close. Try using spheres to completely enclose your mesh, but tightly. Then use sphere masks at those locations and sizes instead.

It’s a little bit of a band-aid solution but it wouldn’t be a much more complex shader (it’d be mobile friendly and wouldn’t use custom depth) and it’d let you achieve a result much more like the stencil mask than just with 1 sphere mask