Skip to content

VisibilitySwitch

Entities with a VisibilitySwitch component are shown or hidden based on whether they are seen by the player. They also store information about which team is currently detecting them.

Info

VisibilitySwitchAuthoring requires a team assignment. TeamAuthoring is added automatically, but you still need to choose which team owns this entity. See Team.

Warning

Do not place this component on player units unless you want to use the same visibility data for AI logic. See AI Vision Integration.

Overview

In the ECS version there are multiple related types:

Type Kind Purpose
VisibilitySwitchAuthoring MonoBehaviour Placed on a sub-scene GameObject; baked into ECS at build/enter play mode
DetectionLayer IComponentData Which fog layer(s) can reveal this entity
VisibilityState IComponentData Stores which teams currently detect this entity
DynamicBuffer<CheckPoint> IBufferElementData Local-space sampling positions
FadePercent IComponentData Optional smooth fade value for fade transitions (see Entity Fade Setup)

VisibilitySwitchAuthoring (Inspector)

Add VisibilitySwitchAuthoring to any GameObject inside a Unity sub-scene that should be revealed or hidden by the fog.

Property Type Default Description
Layer VisionLayer R Which vision layer(s) can reveal this entity (see Vision Layers)
Use Center As Checkpoint bool true When enabled, uses the entity's center as a single check point
Check Points Vector2[] [(0, 0)] Array of local XZ offsets for visibility sampling (only visible when "Use Center As Checkpoint" is disabled)
Use Fade Transition bool false When enabled, the entity fades in/out instead of instantly appearing/disappearing. Requires a material with a specially configured shader (see Entity Fade Setup)

Check Points

The Check Points array allows you to sample multiple positions on large entities. An entity is treated as visible as soon as any check point falls inside any matching vision source.

When Use Center As Checkpoint is enabled, the system uses a single point at (0, 0) relative to the entity's transform.