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

Some properties of AudioSource "is not supported anymore"...

Discussion in 'Audio & Video' started by hyogast, Dec 29, 2014.

  1. hyogast

    hyogast

    Joined:
    Feb 24, 2014
    Posts:
    7
    First of all, sorry for my low english level.

    I'm working on an audio manager class and I have a problem. When I want to play a sound in my scene I use a method that creates a gameObject and places it in a position I set. Then the method adds to the gameobject an audiosource that I pass it by parameter and I keep the reference. This way:

    Code (CSharp):
    1. AudioSource source = go.AddComponent<AudioSource>(_source);
    But Unity throws several errors like this:
    - "minVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead."
    - "maxVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead."
    - "rolloffFactor is not supported anymore. Use min-, maxDistance and rolloffMode instead."

    I have tried to add a new audiosource and then copy the properties of _source one by one but I cant copy the rolloffCustom curve, so I don't know what to do.

    Code (CSharp):
    1. AudioSource source = go.AddComponent<AudioSource>();
    2. source.clip = _source.clip;
    Thanks
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    You've never been able to copy the custom curve through script, and this won't be changing in Unity 5 either. The only way to do it is copy the entire component from elsewhere, then change everything else via script. That's what we do in Master Audio.

    Code something like this:

    Code (csharp):
    1.  
    2.   UnityEditorInternal.ComponentUtility.CopyComponent(objWithAudioSource.GetComponent<AudioSource>());
    3.   UnityEditorInternal.ComponentUtility.PasteComponentAsNew(_target);
    4.  
    Not sure if that works outside of a custom inspector class. This copies an AudioSource component from one object to another. Just make sure to delete any AudioSources on the destination object first as well.
     
  3. hyogast

    hyogast

    Joined:
    Feb 24, 2014
    Posts:
    7
    Thanks! it worked great!
     
  4. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    No problem. It took me a bit to figure out this one so I'm spreading the knowledge.
     
  5. hyogast

    hyogast

    Joined:
    Feb 24, 2014
    Posts:
    7
    Hey jerotas. Now I have another problem. The namespaces UnityEditor or UnityEditorInternal are not included when you build for a platform. Those are only included when working in the actual UnityEditor.
     
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Yeah, so only use that script from a custom Inspector script. That's what we do.
     
  7. hyogast

    hyogast

    Joined:
    Feb 24, 2014
    Posts:
    7
    Jerotas, do you know how to solve this problem in a build? It's driving me crazy :(
     
  8. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Yeah I used a conditional compile directive so that that part of code only compiles while in the editor, not when exporting. I can look that up if you can't find it. Let me know.
     
    Last edited: Mar 2, 2015
  9. leo-dom

    leo-dom

    Joined:
    Jun 14, 2013
    Posts:
    2
    Hello, I found AudioSource.SetCustomCurve, can I use this for copy custom rolloff now ?
     
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    It sounds like that's what it is. Let me know if it works for you.