Skip to main content

ExampleScripts

This page showcases a variety of example scripts demonstrating what you can do with the Reactional API in Unity provided here for learning purposes.

  • Examples - 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 practice

Examples

Scripts Examples that let you do things with reactional in your game.

Events

OnBarBeatEvent

Event-driven system that fires UnityEvents on every bar or beat.

OnBarBeatEvent
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.
ScaleTaggedMeshesOnBeat
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)

ChangeThemeMacroByDistance

Modulates theme intensity or mood parameters based on distance from a player.

ChangeThemeMacroByDistance
using System;
using System.Collections.Generic;
using Reactional.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;

namespace Reactional.Examples.Events
{
/// <summary>
/// This script dynamically updates a theme control parameter based on the distance between a player and any object transform in a list.
/// The control value is normalized between a minimum and maximum distance.
// ... (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

TriggerThemeControlOnCollision
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.

TriggerTrackOnCollision
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.

AnimationBeatSync
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.

InstrumentOverride
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.

PitchAdjustingSFX
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.

TriggerClipOnBeat
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.

CameraPulseOnBeat
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.

TrackProgressBar
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.

VisualEffectGraphPulseOnBeat
/*  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.

VisualEffectsGraphOnNoteEvent
/*  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

ReactionalFmodCallback
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.)
URP_LightAndPostController
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
LogSpectrumVisualizer
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
AudioSourcePool
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)