top of page

Script-Driven Unity VFX & Shaders
​
Skills: VFX (Particle System & VFX Graph), Shader Graph & Custom Shaders, Animation
Tools: Unity 6

1. Character Power Up

​

Overview

This power-up effect brings together Unity's VFX Graph, Shader Graph, and a lightweight C# script to drive energy convergence, particle bursts, and a dynamic character glow.

​

Technical Breakdown 

  • Bind Particles directly to the Character

    • Set Up Skinned Mesh Data: In VFX Graph, add a Position (Skinned Mesh) block to spawn particles over the character's body mesh. Ensure Read/Write Enabled is turned on in your character mesh import settings.

    • Handle Transforms: Use a Set Position block linked to a Transform property, then bind this property in Unity to the root bone of the character skeleton using a VFX Property Binder (Transform Binder).

    • Configure Spawn & Size: Set the spawn context to a single burst. Add a Set Size over Life block with a curve tapering from big to small, and set particle colors using an HDR property for a strong glow.

​

  • Create the Character Glow (Shader Graph)

    • Shader Graph Setup: Create a new Universal Render Pipeline (URP) Lit Shader Graph. Add a Fresnel Effect node and multiply it with an HDR Color property. Connect the result into the Emission output slot.

    • Apply to Character: Generate a material from this shader, check Allow Material Override in the Graph Inspector, and add it as a secondary material slot on the character's Skinned Mesh Renderer.

    • Animate Intensity: Open Unity's Animation window, duplicate the character's power up animation clip, and record keyframes that rapidly boost the HDR emission intensity right as the character powers up, then drop it back down.

​

  • Add Anticipation (Inward Energy Particles)

    • Sphere Emission: Duplicate the particle context in VFX Graph. Remove the Skinned Mesh references and add a Set Position (Sphere) block centered on the character.

    • Inward Motion: Use Set Velocity from Direction & Speed (Spherical) pointing inward to make particles rush toward the character center.

    • Particle Cleanup & Stretch: Place a Kill (Sphere) block at the center so particles vanish upon hitting the character. Set particle orientation to Along Velocity to create stretched energy streaks.

​

  • Add the Flash & Timing Delays

    • Impact Flash: Add a third single-burst particle system with a short lifetime and a high size/scale value centered at the body midpoint to act as a burst flash.

    • Pre-Loop Delay: In the VFX Graph spawn inspector, set the delay mode to Before Loop to align the main particle burst with the peak moment of the character animation.

​​

  • The Script (CharacterPowerUp.cs)

    • Create a C# script named CharacterPowerUp.cs in your project's Assets folder and paste the following code:

​

​

​

​

  • Setting Up in Unity 

    • Attach Script: Drag CharacterPowerUp.cs onto your character's GameObject in the Unity Hierarchy.

    • Assign References: Drag your character's Animator and Visual Effect components into the inspector slots.

    • Set Up VFX Property Binder: On your VisualEffect component, add a Transform Binder under the Property Binders section to bind your skeleton target to the graph's Transform property.

    • Animation Event: At the final frame of your power-up animation clip, add an Animation Event calling OnPowerUpComplete() so the player can power up again when ready.​

2. Dragon Dissovle Shader

Overview
Creating a disintegrate and dissolve effect combines a Dissolve Shader built in Shader Graph with a VFX Graph particle system, all synchronized through C#.


 

Technical Breakdown

  • Build the Dissolve Shader (Shader Graph)

    • PBR Base Setup: Create a new URP Lit Shader Graph. Set up properties for base color, Albedo texture, metallic, smoothness, and normal maps, connecting them to their respective PBR inputs on the Fragment block. Enable Allow Material Override in the Graph Inspector.

    • Dissolve Noise & Clipping: Add a Simple Noise node and feed its scale from a float property. In the Graph Settings, enable Alpha Clipping. Connect a Dissolve Amount slider property (range 0 to 1) directly into the Alpha Clip Threshold.

    • Dissolve Edge Glow: Pass the noise output into a Step node. Add a tiny offset value to the Dissolve Amount property and feed it to the Step node's threshold. Multiply the output with an HDR Color property and plug the result into Emission to create a glowing edge along the dissolving border.
       

  • Bind Surface Particles (VFX Graph)

    • Skinned Mesh Emitter: Create a new Visual Effect Graph. Add a Position (Skinned Mesh) block inside the Initialize Context to force particles to spawn directly across the surface of the mesh. Ensure Read/Write Enabled is checked in your model's import settings.

    • Transform Binding: Use a Set Position block fed by a Transform Position node. Add a Transform property in the graph and link it to the character's root bone using a Transform Binder on the VFX component.

    • Particle Dynamics & Motion: Set a short particle lifetime and give particles an upward velocity vector. Set size over lifetime to shrink from big to small, and set color over lifetime to fade out the alpha channel.

    • Secondary Burning Layer: Duplicate the particle context to create a dark, ash-like particle layer that rises slightly slower and renders behind the bright glowing particles to give the disintegration extra depth.
       

  • Control Timing & Delay

    • Spawn Constraints: In the VFX Graph Spawn Context, set the Loop Duration to a constant and Loop Count to 1 so the particle burst fires once instead of looping continuously.

    • Pre-Loop Delay: If you want the particle burst to align with character animations or shader timing, set the delay mode in the Spawn Inspector to Before Loop.

 

  • The Script (CharacterPowerUp.cs)

    • Create a C# script named DissolvingController.cs and attach it to the parent GameObject containing your character or object:

​

​

​

  • How the Effect is Script-Driven 

    • Interpolating Material Properties: Running an IEnumerator coroutine that smoothly steps the _DissolveAmount float on all sub-materials from 0 (fully visible) to 1 (completely dissolved).

    • Cross-System Synchronization: Firing vfxGraph.Play() at the exact moment the material dissolve sequence begins, ensuring particles erupt right as the mesh begins eroding.

    • Input & State Control: Detecting player input (via Spacebar or hotkey) while enforcing a isDissolving flag to prevent double-triggering or interrupting active dissolve sequences.

​

  • Benefits of Script-Driven Control

    • Seamless Visual Cohesion: Synchronizing shader erosion and particle spawns frame-by-frame via code prevents visual disconnects where particles appear before or after the mesh actually dissolves.

    • Flexibility Across Multiple Materials: The script loops through all material slots on a SkinnedMeshRenderer automatically, applying the dissolve threshold across multi-material complex meshes without needing manual animation tracks for each material.

    • Resource Efficiency: Particle systems remain idle when inactive. Triggering Reinit() and Play() through code ensures GPU resources aren't wasted processing hidden emitters during regular gameplay.

    • Unity 6 Engine Compatibility: Supporting conditional #if ENABLE_INPUT_SYSTEM checks ensures the script compiles cleanly in Unity 6 whether using the Input System package or classic Input Manager.

bottom of page