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

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:

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.

AudioSource source = go.AddComponent<AudioSource>();
source.clip = _source.clip;

Thanks

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:

  UnityEditorInternal.ComponentUtility.CopyComponent(objWithAudioSource.GetComponent<AudioSource>());
  UnityEditorInternal.ComponentUtility.PasteComponentAsNew(_target);

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.

Thanks! it worked great!

No problem. It took me a bit to figure out this one so I’m spreading the knowledge.

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.

Yeah, so only use that script from a custom Inspector script. That’s what we do.

Jerotas, do you know how to solve this problem in a build? It’s driving me crazy :frowning:

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.

Hello, I found AudioSource.SetCustomCurve, can I use this for copy custom rolloff now ?

It sounds like that’s what it is. Let me know if it works for you.