Use the Outline Shader

The outline of interactable objects is handled by a Render Feature in URP. You can find the source basis for it here:

The example project is already setup to use the Outline Shader. If you're implementing it from scratch then you go to your URP Pipeline Renderer file and add the Outline Render Feature to it. You'll need to assign some of the material references in order for it to work.

You can set the Layer Mask to whatever you want, and you can add multiples of this AFAIK, which would allow you to use this shader for other things in your game and set different colors.

To use it in on an object, the MeshRenderer or SkinnedMeshRenderer that you want to outline must BE ON THE SPECIFIED UNITY LAYER and also BE ON THE SPECIFIED RENDER LAYER. Notice the image.

Below is example usage code. The interaction system requires a list of MeshRenderer or SkinnedMeshRenderer components and we just loop through them during hover in/out events to swap the renderingLayerMask property around. The GameObjects must ALSO be on the specified layer in the URP renderer outline feature settings because that is the filter on which it determines which GameObjects should be evaluated for the outline.

In this case, the above image highlights the GameObjects that will be getting the outline are already on the Interactable layer and the Rendering Layer Mask is also set to Outlines, which is the conditions for the Render Feature to include it.

Last updated

Was this helpful?