Skip to content

Entity Fade Setup

This page explains how to set up entities with smooth fade transitions when they become visible or hidden by the fog of war.

Overview

Entities with the VisibilitySwitch component can either appear/disappear instantly or fade smoothly. To enable fade transitions, you need to configure the global fade duration in FogOfWarManager, enable fade on the entity's VisibilitySwitchAuthoring component, and create a material with a shader that supports the fade effect.

Setup Steps

1. Configure Global Fade Duration

The global fade duration for all entities is controlled in the FogOfWarManager component:

  • Select the GameObject with the FogOfWarManager component in your scene
  • Set the Entity Fade Duration property to the desired fade time in seconds (e.g., 0.2 for a quick fade, 1.0 for a slower fade)

2. Enable Fade in VisibilitySwitchAuthoring

On each entity that should fade:

  1. Select the entity GameObject
  2. Find the VisibilitySwitchAuthoring component
  3. Enable the Use Fade Transition checkbox

3. Create Material with Shader Graph

The entity needs a material with a shader that supports fade transitions. Follow these steps to create it in Shader Graph:

Step 1: Create a new Shader Graph

  • Right-click in Project window → Create → Shader Graph → URP → Lit Shader Graph (or Unlit, depending on your needs)

Step 2: Set Shader to Transparent

  • Open the Shader Graph
  • In the Graph Inspector, find the Surface Type setting
  • Change it from Opaque to Transparent

Step 3: Add FadePercent Property

  • In the Blackboard, click the + button to add a new property
  • Select Float
  • Name it exactly FadePercent (case-sensitive)
  • In the property settings:
  • Set Reference to FadePercent (no underscore)
  • Set Shader Declaration to Hybrid Per Instance (this is critical for ECS rendering)
  • Set Mode to Slider
  • Set Min to 0
  • Set Max to 1
  • Set Default to 1

Step 4: Wire Up the Fade Effect

  • Drag the FadePercent property into the graph
  • Connect it to the Alpha input of the Master Stack (for a simple alpha fade)
  • Or use it in more complex ways (multiply with texture alpha, use in a dissolve effect, etc.)

Step 5: Create Material

  • Save the Shader Graph
  • Create a new Material using this shader
  • Assign the material to your entity's Renderer