How to Use Raycasting with Render Custom Depth

I can’t seem to figure out how to get my ray cast system to differ between two actors. Basically whats happening is the ray cast set’s an actor variable called Actor Traced. This Actor Traced variable is then casted against BP_MasterItem and if it is a child of that blueprint then promote to a variable called Master Item.
So 2 Variables. Actor Traced – and – Master Item.
Once this Master Item is set, we then get the information associated with that blueprint from a Data Structure I made, (S_ItemData) then we break the structure and get the Item Name. If the Item has a name that is not null then set item text. My HUD blueprint then picks it up from there. In my HUD blueprint my Item Name text gets set to that of the Item that was traced. So Now Actor Traced > sets Master Item > Gets Item Name > HUD sets Item to same as Master Items, Item Data.

Then we again check to make sure Item Name (HUD) is not null, if this is true then we set Render Custom Depth on the Master Items Primitive Component (Mesh), if this is null then we set the Render Custom Depth to false.

Again this all works Great, but problem is When I set Actor Traced, and it checks against my Cast, and is confirmed, it sets the Render Custom Depth. I need to figure out a way that when I set render custom depth on an object, there isn’t already an object being rendered. Is there a way to do this?
By the way all of these are on Event Tick Events.

First Person Blueprint - Trace Item Function Part 1

First Person Blueprint - Trace Item Function Part 2

HUD Blueprint - Set Visibilities Part 1

HUD Blueprint - Set Visibilities Part 2

Here’s a video link of what I am experiencing.

So you basically want always only one item being drawn with custom render depth right?

The basic idea is that you need to take care of the custom render depth whenever you do anything with your Actor Traced variable. Before you set it to “none”. Remove the custom render depth from the actor stored within it. Before you set a new actor, make sure to remove the custom render depth from your current actor (if your current variable isn’t “none”).

If you implement this everywhere (ideally create macros to set and clear the variable and use those everywhere to reduce potential mistakes now or in the future due to forgetting one occurrence) it should take care of everything.

I hope I understood the question correctly and this helped! :slight_smile:

Cheers

This is the basic Idea I thought I needed to take just wasn’t sure how to implement it, I’ve never used macros. I’ll have to look into them, but I’ll give this a shot in the morning! Thanks for the quick reply!

It works! I just have one a little issue (not related to the ray tracing but caused by my fix that I have to now fix) But other than that, superb suggestion!