Scripting Examples | Callback Handler

11. Scripting Examples | Callback Handler

    You can provide a custom handler that will receive callbacks from FMOD when certain events occur. To do this, create a class that inherits from FMODUnity.PlatformCallbackHandler:

    using System;
    using UnityEngine;
    
    [CreateAssetMenu(menuName = "My FMOD Callback Handler")]
    public class MyFMODCallbackHandler : FMODUnity.PlatformCallbackHandler {
        public override void PreInitialize(FMOD.Studio.System studioSystem, Action<FMOD.RESULT, string> reportResult)
        {
            FMOD.RESULT result;
    
            FMOD.System coreSystem;
            result = studioSystem.getCoreSystem(out coreSystem);
            reportResult(result, "studioSystem.getCoreSystem");
    
            // Set up studioSystem and coreSystem as desired
        }
    }
    

    Create a callback handler object:

    Create Callback Handler

    Set the Callback Handler field in the FMOD for Unity settings to your callback handler object:

    Set Callback Handler

    FMOD will now call the PreInitialize method on your object just before initializing the FMOD Studio system.