Selection highlight of Blueprints with Multiple Meshes

I’m making a citybuilder game in UE5 and struggling to make a building selection highlight.

I’ve gone through lots of tutorials and tried taking apart the Survivor Vision plugin, but each tutorial only works on a single character or a single static mesh and doesn’t give a unified outline for multiple selected meshes - or multiple meshes within the same selected Blueprint object in my case and my buildings are modular and made up of lots of static meshes.

Interestingly, the one place I’ve seen an effect which would be perfect is from Unreal Engine itself: the yellow object selection highlight that we all know and love - it gives a single outline for the entire selection - exactly what I want (once I tweak colours and line thicknesses). Does anyone know a way of replicating this?

I’m not good enough with C++ to even know where to find it in the engine source code. A pointer to a working setup using materials/post process would be ideal. Thanks in advance everyone!

1 Like

Hey there @renegaderich! I’m not particularly well versed on the engine side highlighting but generally when I do something like this I tend to use stencil buffer outlines. They will combine if put together and can choose to be occluded or not. You may have already tried this however.

Disclaimer: Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.

That tutorial got me a lot of the way there. Thank you!

To get it to highlight all of the static meshes within the blueprint, I used this bit of code to loop through everything and add the meshes to the depth pass.

A few interesting observations:

This doesn’t currently work with Nanite - not a huge problem for me, but this might save someone a headache! If anyone knows how to get it working with Nanite, I’m curious, but it’s not a priority for me.

The unchecked Set Render Custom Depth in the lower Unselected path is needed to make sure only the selected object is involved in choosing where the outline goes. If that node isn’t included, it assumes that you still want this (previously selected) object to occlude the new selection - meaning if your selected object is behind a previously selected object, you only see a partial outline. This might be desired behavior for someone!

Transparent materials like glass don’t get caught in the depth pass, so if you have a building with windows you can see right through, you get outlines around the window frames. Can look a bit messy with a greenhouse!

Oh yes! Forgot to mention, nanite meshes make this method unviable unfortunately. I’ve seen a couple of members speculating about workarounds such as having a mega-low poly SM version of the object and only rendering it in the stencil layer to still be able to use this method. A bit hacky but would work for projects that aren’t pushing the need for optimization. Another alternative mentioned is decals, but personally I don’t know how that method would work but it’d 100% be more efficient if you could get it to work well.

Hope this helps!