Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to store changes in AudioSettings from Editor Script

Discussion in 'Scripting' started by eliashodel, Aug 16, 2023.

  1. eliashodel

    eliashodel

    Joined:
    Jan 25, 2019
    Posts:
    18
    Hi There

    I want to change the Spatializer Plugin from a Editor Script and have this Code that works:
    Code (CSharp):
    1. public static void SetSpatializerPlugin()
    2. {
    3.     if (SpatializerIsAvailable())
    4.     {
    5.         AudioSettings.SetSpatializerPluginName("My_Spatializer");
    6.         Debug.Log($"Set Spatializer Plugin to {AudioSettings.GetSpatializerPluginName()}");
    7.     }
    8.     else
    9.     {
    10.         Debug.LogError($"Spatializer Plugin could not be set to {AudioSettings.GetSpatializerPluginName()}! It was not found in the Project.");
    11.     }
    12. }
    This works fine, however the change is not stored to disk and will be gone when i start the project the next time.
    The ususal solution to this like marking the Component as Dirty with EditorUtility.SetDirty() or using Undo.RecordObject() do not work, since there is no UnityEngine.Object that can be passed to these methods.

    How am i supposed to make my change persist over a Restart?

    Thanks for your help!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
  3. eliashodel

    eliashodel

    Joined:
    Jan 25, 2019
    Posts:
    18