Search Unity

Question AudioReverbPreset Expose Properties

Discussion in 'Scripting' started by dizzymediainc, Jul 27, 2020.

  1. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
    Hello,

    So I am trying to expose the properties of the AudioReverbPreset's., such as General, Room, Etc., ideally i'd like to just reference those like so:

    Code (CSharp):
    1. public AudioReverbPreset initReverbPreset;
    2.  
    3. public ReverbProps initReverbProps;
    4.  
    5.     [System.Serializable]
    6.     public class ReverbProps {
    7.  
    8.         [Range(-10000, 0)]
    9.         public int room;
    10.    
    11.         [Range(-10000, 0)]
    12.         public int roomHF;
    13.    
    14.         [Range(-10000, 0)]
    15.         public int roomLF;
    16.    
    17.         [Range(0.1f, 20)]
    18.         public float decayTime;
    19.    
    20.         [Range(0.1f, 2)]
    21.         public float decayHFRatio;
    22.    
    23.         [Range(-10000, 1000)]
    24.         public int reflections;
    25.    
    26.         [Range(0, 0.3f)]
    27.         public float reflectionsDelay;
    28.    
    29.         [Range(-10000, 2000)]
    30.         public int reverb;
    31.    
    32.         [Range(0, 0.1f)]
    33.         public float reverbDelay;
    34.    
    35.         [Range(1000, 20000)]
    36.         public float hfReference;
    37.    
    38.         [Range(20, 1000)]
    39.         public float lfReference;
    40.    
    41.         [Range(0, 100)]
    42.         public float diffusion;
    43.    
    44.         [Range(0, 100)]
    45.         public float density;
    46.    
    47.     }//ReverbProps
    48.  
    49. initReverbProps.room = initReverbPreset.room;
    50.  
    51.  

    initReverbProps.room = initReverbPreset.room;

    But obviously that doesn't work, storing the properties in a separate class to display them inside of a custom editor is my only work around so far but in order to do that i need to have an object with the reverb zone active in the game scene and update that specific component to retreive the proper values per reverb preset.

    Instead of creating and destroying a gameobject/reverb component over and over again after every editor value update, it would be more ideal to simply grab the preset default values and refer to those.

    The question is, how? There is no api that i can see that suggests you can do this.

    The only thing i have found is here: https://docs.unity3d.com/ScriptReference/AudioReverbZone-reverbPreset.html

    Which suggest you can "Get reverb preset properties." yet provides no api to do so.

    Thoughts?
     
    Last edited: Jul 27, 2020
  2. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
    Honestly if that solves your problem and it's only an editor time thing, jeez, that's nothing, just code it that way and get back to working on fun stuff. You can DestroyImmediate() and Instantiate() quite a lot of stuff at editor time without too much sweat.
     
  4. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
    Yea technically i could, just concerned about crashes due to too many destroys being called.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
    Unless there is a bug in Destroy, I don't believe this is a thing.
     
  6. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
    You'd hope not :p but better to be safe than sorry.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,743
    I'm sorry, you have lost me with this line of reasoning. This line of reasoning would naturally lead to "let's just not call ANY functions because we might crash."

    Good luck!
     
  8. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
    Well it makes perfect sense if you are making a custom asset that you would sell for others to use :p

    It would be ideal that the custom asset should cause as little problems as possible and not introduce engine crashing instances, as the user could be doing anything, possible not have saved their scene in a while and then bam, engine crashes.

    Thus the best approach would be to make a custom asset that performs well and does what's needed, without an extra impact on the users opened instance of the engine/project.

    So yes it makes perfect sense, however if it were a personal asset, i would still be concerned, lazy coding is not something i agree with :p