β­•Selection Indicator

Learn how selection indicators work

Overview

The selection system supports few ways to set up indicators with SelectableUnit component. While indicators are optional, they enhance the player experience by visually highlighting selected units.

Selection indicator is defined per game object unit as you might need to resize indicators for different units, or perhaps different visuals for various unit types that you may support in your game.

Indicator example

Supported components

There are few components already provided by Unit Selection package for easy setup. Pick the one which suits your game needs best. If you do not find one that does, you can implement your own and if you believe a common use case is missing, feel free to drop a feature request on Discord or send us an Email.

Sprite Renderer

SpriteRendererSelectionIndicator provides you with options to set different sprites and colors for selected or highlighted states.

SpriteRendererSelectionIndicator component

Rendering technique

You can use Sprite renderer to render simple texture in world. You can set your own material, flip texture, add sorting layer, etc. This technique is shown in the Demo scene and is provided with 2 different ring textures (Selection Indicator - Sprite).

Limitations: This works well when you have a plain for terrain and no hills as it does not project to terrain/ground mesh.

Mesh Renderer

MeshRendererSelectionIndicator provides you with options to set different mesh and materials for selected or highlighted states.

MeshRendererSelectionIndicator component

Rendering technique

You can create your own custom shader for rendering textures using depth and use it with MeshRenderer. There are few approaches, but one that works very similar to Decals can be seen in this youtube tutorial.

Limitations: Simple shaders like the one in the link above will project the texture on all meshes, even units and trees alike. For desired effect more complex solution might be needed, however there are still Decals.

Game Objects & Decals

GameObjectSelectionIndicator provides you with simple interface to specify a game object for selected state and another for highlighted state.

GameObjectSelectionIndicator component

Rendering technique

One of the most common practices is most likely Unity's Decals (Unity documentation). Specially when using URP and HDRP.

Limitations: As far as I am aware only High-Definition Rendering Pipeline can specify which layers to project the texture on. Universal Rendering Pipeline cannot specify layers and Built-in Rendering Pipeline projectors have more limitations.

Customise

If none of the existing options suits your needs, you are free to implement custom components for a tailored approach with ASelectionIndicator .

public abstract class ASelectionIndicator : MonoBehaviour
{
    public abstract void Select();
    public abstract void Highlight();
    public abstract void Clear();
}

Last updated