Skip to content

VisibilitySwitch

The VisibilitySwitch component enables GameObjects to receive events about visibility state changes in the fog of war system. The object is considered visible when at least one of its checkpoint positions is within range of any VisionSource. The object is considered hidden when all checkpoints are outside of any vision range.

Fader

The component includes an optional built-in Fader that provides smooth fade-in and fade-out transitions for the configured renderers. The fader automatically animates visibility changes and enables or disables the target renderers at the appropriate times. You do not need to toggle renderer states in your On Become Visible / On Become Invisible handlers. Enabling the fader increase computational cost.

Usage

  1. Add the VisibilitySwitch component to any GameObject that should receive events about fog visibility changes.

  2. Configure the component properties in the Inspector.

Inspector Properties

VisibilitySwitch Inspector

  • Use Center As Checkpoint: Determines whether to use only the GameObject's center position as a single checkpoint (when checked) or to allow definition of custom checkpoint positions (when unchecked).

  • Check Points: (This property appears only if "Use Center As Checkpoint" is unchecked) A list of Vector2 positions relative to the GameObject's position and rotation. The object is considered visible if any checkpoint position is within range of a VisionSource.

  • On Become Visible: A UnityEvent triggered when the object transitions from hidden to visible state.

  • On Become Invisible: A UnityEvent triggered when the object transitions from visible to hidden state.

  • Is Fade Enabled: Enables or disables fade transition effects for renderers.

  • Fade Duration (min 0.01): (This property appears only if "Is Fade Enabled" is checked) The duration in seconds for fade in/out transitions.

  • Material Fade Percent Name: (This property appears only if "Is Fade Enabled" is checked) The name of the material shader property to control during fade transitions (default: _FadePercent).

  • Renderers: (This property appears only if "Is Fade Enabled" is checked) An array of Renderer components to which the fade effect will be applied.

Public API

  • event Action OnBecomeVisible - A C# event triggered when the object becomes visible. Can be subscribed to for programmatic responses.

  • event Action OnBecomeInvisible - A C# event triggered when the object becomes hidden. Can be subscribed to for programmatic responses.