Search code examples
unity-game-engineaudio

OnAudioFilterRead: where are VU meter and time spent shown in the editor?


In the documentation of MonoBehaviour.OnAudioFilterRead, the following is written:

If OnAudioFilterRead is implemented a VU meter is shown in the Inspector displaying the outgoing sample level. The process time of the filter is also measured and the spent milliseconds are shown next to the VU meter. The number turns red if the filter is taking up too much time, meaning the mixer will be starved of audio data.

But these widgets are nowhere to be seen in the Inspector...

There is also this other option in a mixer's context menu:

enter image description here

But again, nothing is ever shown anywhere in the editor...

The registry key this option updates is indeed set to 1 but that's all.

What I've tried:

Using Unity 2022.3.3f1, created a brand new project.

Created the most basic setup and added this script:

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public float Volume = 0.5f;

    public void OnAudioFilterRead(float[] data, int channels)
    {
        for (var i = 0; i < data.Length; i++)
        {
            data[i] *= Volume;
        }
    }
}

The callback indeed works as I can change volume but no VU nor CPU meter:

enter image description here

Whether or not a mixer is plugged-in makes no difference.

Tried to restart Unity but that didn't change anything.

Question:

Why are the VU and CPU meters nowhere to be seen on the component?


Solution

  • For whatever reason, an Editor must be created for it to appear:

    The component:

    using UnityEngine;
    
    namespace Whatever
    {
        public class WhateverComponent : MonoBehaviour
        {
            private void OnAudioFilterRead(float[] data, int channels)
            {
            }
        }
    }
    

    The editor:

    using UnityEditor;
    
    namespace Whatever
    {
        [CustomEditor(typeof(WhateverComponent))]
        internal sealed class WhateverComponentEditor : Editor
        {
        }
    }
    

    The result:

    enter image description here