Unity 3D how to find the gameobject which is instantiating a not declared component AudioListener

I have a multiuser application which runs with Photon Unity Network (PUN) and Photon Audio. With Photon Audio, audio is streamed to the PUN server and then sent to all the players in the game. Photon Audio has a wrapper class on top of the core Unity audio classes to do their streaming.

I am using guidance from this forum Output all voice conversations into .wav, .mp3 etc | Photon Engine where it says that to record the full application output mix you can use MonoBehaviour.OnAudioFilterRead if implemented on an object with AudioListener.

The problem is that I cannot find the gameobject which is already creating an instance of AudioListener, so I cannot create my own gameobject with AudioListener because it appears as a second instance.

I tried to use:

    var foundObjects = FindObjectsOfType<AudioListener>();
    Debug.Log("**** " + foundObjects + " : " + foundObjects.Length)

which returns saying there is one active instance of AudioListener:

**** UnityEngine.AudioListener[] : 1
    0x000000014179D92B (Unity) StackWalker::GetCurrentCallstack
    0x000000014179F5DF (Unity) StackWalker::ShowCallstack
    0x00000001417796A0 (Unity) GetStacktrace
    0x0000000140D3F23B (Unity) DebugStringToFile
    0x0000000140D3FA1C (Unity) DebugStringToFile
    0x00000001413FE562 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000000003C8F2F5B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    0x000000003C8F2E44 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x000000003C8F27D5 (Mono JIT Code) [Logger.cs:41] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x000000003C8F2016 (Mono JIT Code) [DebugBindings.gen.cs:103] UnityEngine.Debug:Log (object)
    0x00000000137EDA2B (Mono JIT Code) [PUNManagerStarter.cs:57] PUNManagerStarter:Update ()
    0x00000000008C7392 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007FFD0CA55703 (mono) [mini.c:4937] mono_jit_runtime_invoke
    0x00007FFD0C9A8425 (mono) [object.c:2623] mono_runtime_invoke
    0x00000001410657E5 (Unity) scripting_method_invoke
    0x000000014105B461 (Unity) ScriptingInvocation::Invoke
    0x0000000141498F5B (Unity) MonoBehaviour::CallMethodIfAvailable
    0x000000014149D05F (Unity) MonoBehaviour::CallUpdateMethod
    0x0000000140AC4A86 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    0x0000000140AC567F (Unity) BehaviourManager::Update
    0x0000000140D74BC7 (Unity) PlayerLoop
    0x000000014171983E (Unity) Application::UpdateScene
    0x000000014171B00F (Unity) Application::UpdateSceneIfNeeded
    0x000000014172373A (Unity) Application::TickTimer
    0x00000001417EEA1C (Unity) CrashCallback
    0x00000001417F0664 (Unity) WinMain
    0x0000000141AD38E4 (Unity) strnlen
    0x00007FFD4A4A3034 (KERNEL32) BaseThreadInitThunk
    0x00007FFD4CF21431 (ntdll) RtlUserThreadStart

and:

    var al = FindObjectOfType<AudioListener>();
    Debug.Log("**** " + al + " : " + al.name);

which returns:

**** Head Target (UnityEngine.AudioListener) : Head Target
    0x000000014179D92B (Unity) StackWalker::GetCurrentCallstack
    0x000000014179F5DF (Unity) StackWalker::ShowCallstack
    0x00000001417796A0 (Unity) GetStacktrace
    0x0000000140D3F23B (Unity) DebugStringToFile
    0x0000000140D3FA1C (Unity) DebugStringToFile
    0x00000001413FE562 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x000000003C8F2F5B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    0x000000003C8F2E44 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x000000003C8F27D5 (Mono JIT Code) [Logger.cs:41] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x000000003C8F2016 (Mono JIT Code) [DebugBindings.gen.cs:103] UnityEngine.Debug:Log (object)
    0x00000000137EDBF2 (Mono JIT Code) [PUNManagerStarter.cs:60] PUNManagerStarter:Update ()
    0x00000000008C7392 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007FFD0CA55703 (mono) [mini.c:4937] mono_jit_runtime_invoke
    0x00007FFD0C9A8425 (mono) [object.c:2623] mono_runtime_invoke
    0x00000001410657E5 (Unity) scripting_method_invoke
    0x000000014105B461 (Unity) ScriptingInvocation::Invoke
    0x0000000141498F5B (Unity) MonoBehaviour::CallMethodIfAvailable
    0x000000014149D05F (Unity) MonoBehaviour::CallUpdateMethod
    0x0000000140AC4A86 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    0x0000000140AC567F (Unity) BehaviourManager::Update
    0x0000000140D74BC7 (Unity) PlayerLoop
    0x000000014171983E (Unity) Application::UpdateScene
    0x000000014171B00F (Unity) Application::UpdateSceneIfNeeded
    0x000000014172373A (Unity) Application::TickTimer
    0x00000001417EEA1C (Unity) CrashCallback
    0x00000001417F0664 (Unity) WinMain
    0x0000000141AD38E4 (Unity) strnlen
    0x00007FFD4A4A3034 (KERNEL32) BaseThreadInitThunk
    0x00007FFD4CF21431 (ntdll) RtlUserThreadStart

Any help about how to find the gameobject which instantiating AudioListener would be greatly appreciated.

Update 1: The AudioListener might be instantiated by the only camera in the scene, and that camera might come from an external library I am using called InstantVR. However, it happens the same as with the AudioLister component: I cannot find the script instantiating the camera. Using var cam = FindObjectOfType<Camera>(); I get: Headcam (UnityEngine.Camera) : Headcam

This answer on another thread tells you how to handle this.

Hi @Doug_B , I previously checked that post. I only detected one Camera in the scene, which I suppose is instantiating the AudioListener. In this application I am using the InstantVRlibrary, which I suppose renders the camera, but I cannot find the camera script either. This is all what I get when I search for the camera object: Headcam (UnityEngine.Camera) : Headcam.

In the application I was debugging, there was a combination of [HideInInspector], HideFlags.HideInHierarchy, and HideFlags.HideInInspector applied to some gameobjects and components from third-party libraries.

I found the required gameobjects and components using the following code, and checking the Hierarchy and the Inspector while the application was running:

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            GameObject[] foundObjects = FindObjectsOfType<GameObject>();
            Debug.Log("**** " + foundObjects + " : " + foundObjects.Length);
            var count = 0;
            if (foundObjects != null)
            {
                foreach (GameObject foundObject in foundObjects)
                {
                    count++;
                    if (foundObject.hideFlags == HideFlags.HideInHierarchy || foundObject.hideFlags == HideFlags.HideInInspector)
                    {
                        foundObject.hideFlags = HideFlags.None;
                        Debug.Log("**** foundObject: " + foundObject + " : foundObject Name: " + foundObject.name + " - Count: " + count);
                    }
                }
            }
        }
    }

The hidden objects were then accessible from the Hierarchy. Hope it helps someone else.