ExampleScripts
This page showcases a variety of example scripts demonstrating how to work with the
Reactional Plugin in Unity
. Some scripts are included directly in the plugin as part of the shipped package, while others are additional examples that we've provided here for learning purposes.
- Bundeled In Plugin - Official scripts included in the plugin package (v1.0.2)
- Integrations - System-specific implementations
How To Use These Scripts
- Create a new script with the same name and place them in your Unity project's
Assets
folder- Copy the script, paste it into your new script
- Read the script Summary that will explain any specific setup steps and best pratice
Bundeled In Plugin
Scripts included in the Reactional Unity plugin (v1.0.2) and provide core functionality.
Events
OnBarBeatEvent
Event-driven system that fires UnityEvents on every bar or beat.
using Reactional.Core;
using UnityEngine;
namespace Reactional.Examples.Events
{
/// <summary>
/// Triggers an event on every beat within a musical bar, allowing you to DO SOMETHING in sync with the music.
/// This script listens for bar beat events from the Reactional Engine and executes actions on each beat.
/// It can be used to animate objects, trigger effects, or sync gameplay mechanics to the rhythm.
/// </summary>
/// <para/>
/// <para/> Usage:
// ... (click to expand)
ScaleTaggedMeshesOnBeat
Scales all tagged meshes in sync with the beat.
- Note: Works best with meshes that have a centered or bottom pivot.
using System.Collections.Generic;
using Reactional.Core;
using Reactional.Playback;
using UnityEngine;
namespace Reactional.Examples.Events
{
/// <summary>
/// This script scales tagged meshes in the scene based on the beat frequency associated with their tag.
/// It detects all meshes with specified tags and applies scaling animations synchronized to the music.
/// </summary>
/// <para/>
// ... (click to expand)
SetThemeControlByDistance
Modulates theme intensity or mood parameters based on distance from a player.
using UnityEngine;
namespace Reactional.Examples.Events
{
/// <summary>
/// This script dynamically updates a theme control parameter based on the distance between two objects.
/// The control value is normalized between a minimum and maximum distance.
/// </summary>
///
/// <para/> Requirements:
/// <list type="bullet">
/// <item><description> Assign two objects (object1 and object2) in the inspector.</description></item>
// ... (click to expand)
TriggerThemeControlOnCollision
Triggers musical Theme events when the player enters or exits a collider. Useful for syncing music elements (like Parts, Macros, or Stingers) to in-game locations or moments
using Reactional.Playback;
using UnityEditor;
using UnityEngine;
using Reactional.Editor;
namespace Reactional.Examples.Events
{
/// <summary>
/// This script triggers theme control events when the player enters or exits a collider.
/// It supports various theme control types such as Macros, Parts, Stingers, and Playables.
/// </summary>
/// <para/>
// ... (click to expand)
TriggerTrackOnCollision
Plays a specific Reactional Track when the player enters a trigger collider and can optionally stop the track with a smooth fade when exiting.
using Reactional.Core;
using UnityEditor;
using UnityEngine;
using Playlist = Reactional.Playback.Playlist;
using Reactional.Editor;
namespace Reactional.Examples.Events
{
/// <summary>
/// Plays a Reactional music track when the player enters a trigger collider,
/// and optionally stops it when the player exits the collider.
/// </summary>
// ... (click to expand)
Animation
AnimationBeatSync
Synchronizes an object's animation state or behavior to the beat of the music using a configurable animation curve.
using System.Collections.Generic;
using Reactional.Playback;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
namespace Reactional.Examples.Animation
{
/// <summary>
/// This script synchronizes animations with the beat of the music, allowing for either multiple animations
/// within an animator controller or a single animation clip to be dynamically adjusted.
/// The animation speed and timing are controlled using an animation curve for more flexibility.
// ... (click to expand)
Audio
InstrumentOverride
Override parameters for a specific instrument in the currently playing theme. Lets you modify pulse rate, pitch, and dynamics.
using System.Collections;
using UnityEngine;
namespace Reactional.Examples.Audio
{
/// <summary>
/// Overrides a sampler instrument in the currently playing Reactional theme.
/// Allows dynamic control over how the instrument plays, including pitch, dynamics, pulse rate, and legato.
/// </summary>
/// <para/>
/// <para/> Requirements:
/// <list type="bullet">
// ... (click to expand)
PitchAdjustingSFX
Modifies pitch of a sound effect in real-time based on beat/mood changes in the music.
using System;
using System.Collections.Generic;
using Reactional.Core;
using Reactional.Playback;
using UnityEngine;
namespace Reactional.Examples.Audio
{
/// <summary>
/// Represents an audio asset that can be modified and played within the Reactional system.
/// Stores the audio clip, source, pitch, and quantization value for precise playback synchronization.
/// Used in conjunction with <see cref="PitchAdjustingSFX"/> to harmonize non-reactional SFX with music.
// ... (click to expand)
TriggerClipOnBeat
Plays an AudioClip on beat.
using UnityEngine;
using System.Collections.Generic;
using Reactional.Playback;
using UnityEngine.Audio;
using Random = UnityEngine.Random;
namespace Reactional.Examples.Audio
{
/// <summary>
/// This script plays random audio clips on specific music beats using the Reactional Engine.
/// It subscribes to quantized beat events and triggers a sound from a predefined list.
/// Set up your preferred audio clips and configure 3D sound settings for optimal spatial audio experience.
// ... (click to expand)
Rendering
CameraPulseOnBeat
Applies pulse-like FOV or camera transforms based on music beat.
using UnityEngine;
namespace Reactional.Examples.Rendering
{
/// <summary>
/// This script dynamically adjusts the camera's field of view (FOV) in sync with music beats,
/// creating a pulsing visual effect.
/// It uses an animation curve to control the zoom intensity over time.
/// </summary>
/// <para/>
/// <para/> Note:
/// <list type="bullet">
// ... (click to expand)
UI
TrackProgressBar
Simple UI element to display current track position visually.
using System.Collections;
using System.Collections.Generic;
using MiniJSON;
using Reactional.Playback;
using UnityEngine;
using UnityEngine.UIElements;
namespace Reactional.Examples.UI
{
/// <summary>
/// This script manages a UI Toolkit progress bar that visualizes the playback progress of the current track in your Reactional Bundle.
/// It retrieves track duration from metadata and updates the bar based on the current music beat.
// ... (click to expand)
VFX
VisualEffectGraphPulseOnBeat
Sends values into a VFX graph that reacts to the beat.
/* UNCOMMENT TO USE
using System;
using System.Collections;
using Reactional.Playback;
using UnityEngine;
using UnityEngine.VFX;
namespace Reactional.Examples.VFX
{
/// <summary>
/// This Script will let you Pulse any Visual Effect Graph with Reactional Engine.
// ... (click to expand)
VisualEffectsGraphOnNoteEvent
Triggers a VFX event on detected music notes.
/* UNCOMMENT TO USE
using Reactional.Core;
using UnityEngine;
using UnityEngine.VFX;
namespace Reactional.Examples.VFX
{
/// <summary>
/// Subscribes to 'NoteOn' events from the Reactional Engine and triggers a Visual Effect Graph.
/// With specific attributes. To pass the data you need to create instance of VFXEventAttribute,
/// fill it with data you want and pass with the event.
// ... (click to expand)
Integrations
This section contains optional scripts that extend Reactional's functionality with other systems:
FMOD
ReactionalFmodCallback
Scripts that bridge Reactional with FMOD audio middleware. Read More Here FMOD Integration
using System;
using UnityEngine;
using System.Runtime.InteropServices;
using FMOD.Studio;
using FMODUnity;
using Reactional.Core;
using FMOD;
class ReactionalFmodCallback : MonoBehaviour
{
public FMODUnity.EventReference eventName;
// ... (click to expand)
Universal Render Pipeline
URP_LightAndPostController
Synchronizes URP lighting and post-processing effects with Reactional's beat system. Uses animation curves to dynamically control:
- Light intensity on any lightsource
- Post-processing volume parameters (bloom, vignette, etc.)
using System;
using System.Collections;
using Reactional.Playback;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace Reactional.Examples
{
/// <summary>
/// Let Reactional Engine alter Light and Post Process effects.
/// </summary>
// ... (click to expand)
Audio System
LogSpectrumVisualizer
This script generates a real-time audio visualizer using Unity's FFT spectrum analysis. It analyzes audio data from an Reactional Manager AudioSource and maps frequency bands to a series of bars that scale dynamically based on the amplitude of each band.
- Maps 64 frequency bands to visual bars
- Multiple growth directions
- Works with any AudioSource
- Make sure mesh prefab has its pivot at the bottom of the mesh for best result
using UnityEngine;
namespace Reactional.Examples
{
/// <summary>
/// This script generates a real-time audio visualizer using Unity's FFT spectrum analysis.
/// It analyzes audio data from an AudioSource and maps frequency bands to a series of
/// bars that scale dynamically based on the amplitude of each band.
/// </summary>
/// <para/>
/// <para/> Usage:
// ... (click to expand)
AudioSourcePool
Creates and manages a pool of reusable AudioSources to optimize performance. Features:
- Prevents runtime allocations
- Auto-recycles finished sources
- Configurable pool size
- Singleton access pattern
using System.Collections.Generic;
using UnityEngine;
public class AudioSourcePool : MonoBehaviour
{
[SerializeField] private int poolSize = 20; // Adjust this based on your max concurrent sounds
public Queue<AudioSource> availableSources = new Queue<AudioSource>();
private int poolCounter = 0; // Tracks the current count of AudioSources in the pool
public static AudioSourcePool Instance { get; private set; }
private void Awake()
// ... (click to expand)
Editor
ThemeControlsData
A base class for building custom behavior scripts that control Theme playback in Reactional. It provides automatic access to Theme data and a built-in UI for choosing and controlling musical elements like Macros, Parts, and Stingers — all through the Unity Inspector.
using System;
using System.Collections.Generic;
using Reactional.Core;
using UnityEditor;
using UnityEngine;
namespace Reactional.Editor
{
/// <summary>
/// Base class for creating Reactional control behaviors with automatic Theme data access.
/// </summary>
/// <para/>
// ... (click to expand)
TrackControlsData
A base class for building custom behavior scripts that control Track playback in Reactional. Handles automatic data polling and provides a ready-to-use custom inspector for selecting and previewing Tracks.
using UnityEngine;
using System;
using System.Collections.Generic;
using Reactional.Core;
using UnityEditor;
namespace Reactional.Editor
{
/// <summary>
/// Base class for creating Reactional control behaviors with automatic Track data access.
/// </summary>
/// <para/>
// ... (click to expand)