5.2.2fa
I made a post here (Frame Rate/CPU: Efficiency Tips & Suggestions for Players & Unity - Unity Engine - Unity Discussions), but also thought I would post under the Audio forums.
At this point AudioSource is the biggest contributor to CPU usage and frame-rate reduction in my game.
The AudioSource uses up massive CPU power as long as it is enabled even if it’s not playing a clip!!!
-Muting the AudioSource does not help
-Setting AudioSource volume to 0 does not help
-Having AudioSource falloff set volume to zero (because you are very far away) does not help
-AudioSource.Stop() does not help
-AudioSource.Pause() does not help
The only 2 ways I’ve found to prevent AudioSource from hogging processing power
-Disable
-Destroy
To replicate the issue where AudioSources are chewing up CPU (even if not playing a clip, or volume is 0) create a new blank scene and add this script to an object. For me the FPS is :
0 Audio Sources: 167FPS
200 Audio Sources: 64FPS
400 Audio Sources: 36FPS
using UnityEngine;
using System.Collections;
public class TestAddAudioSource : MonoBehaviour
{
public int counter;
private void OnGUI()
{
GUI.Label(new Rect(200, 4, 300, 20), "Frame Rate = " + (1f/Time.deltaTime).ToString("0"));
GUI.Label(new Rect(200, 24*1, 300, 20), "Counter = " + counter.ToString());
if (GUI.Button(new Rect(200, 24*2, 300, 20), "Add 200"))
{
for (int i = 0; i < 200; i++)
{
counter++;
gameObject.AddComponent<AudioSource>();
}
}
}
}
Is anybody else having this problem? I’d like to know suggestions on the best way to get around this issue. Thanks in advance.
Edit: Seems only occur in the Editor, and not within an actual build file.