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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'Scripting' started by Towerss, Jul 25, 2018.

  1. Towerss

    Towerss

    Joined:
    Feb 17, 2018
    Posts:
    8
    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 https://forum.photonengine.com/disc...l-voice-conversations-into-wav-mp3-etc#latest 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:

    Code (CSharp):
    1.     var foundObjects = FindObjectsOfType<AudioListener>();
    2.     Debug.Log("**** " + foundObjects + " : " + foundObjects.Length)
    which returns saying there is one active instance of AudioListener:

    Code (CSharp):
    1. **** UnityEngine.AudioListener[] : 1
    2.     0x000000014179D92B (Unity) StackWalker::GetCurrentCallstack
    3.     0x000000014179F5DF (Unity) StackWalker::ShowCallstack
    4.     0x00000001417796A0 (Unity) GetStacktrace
    5.     0x0000000140D3F23B (Unity) DebugStringToFile
    6.     0x0000000140D3FA1C (Unity) DebugStringToFile
    7.     0x00000001413FE562 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    8.     0x000000003C8F2F5B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    9.     0x000000003C8F2E44 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    10.     0x000000003C8F27D5 (Mono JIT Code) [Logger.cs:41] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    11.     0x000000003C8F2016 (Mono JIT Code) [DebugBindings.gen.cs:103] UnityEngine.Debug:Log (object)
    12.     0x00000000137EDA2B (Mono JIT Code) [PUNManagerStarter.cs:57] PUNManagerStarter:Update ()
    13.     0x00000000008C7392 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    14.     0x00007FFD0CA55703 (mono) [mini.c:4937] mono_jit_runtime_invoke
    15.     0x00007FFD0C9A8425 (mono) [object.c:2623] mono_runtime_invoke
    16.     0x00000001410657E5 (Unity) scripting_method_invoke
    17.     0x000000014105B461 (Unity) ScriptingInvocation::Invoke
    18.     0x0000000141498F5B (Unity) MonoBehaviour::CallMethodIfAvailable
    19.     0x000000014149D05F (Unity) MonoBehaviour::CallUpdateMethod
    20.     0x0000000140AC4A86 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    21.     0x0000000140AC567F (Unity) BehaviourManager::Update
    22.     0x0000000140D74BC7 (Unity) PlayerLoop
    23.     0x000000014171983E (Unity) Application::UpdateScene
    24.     0x000000014171B00F (Unity) Application::UpdateSceneIfNeeded
    25.     0x000000014172373A (Unity) Application::TickTimer
    26.     0x00000001417EEA1C (Unity) CrashCallback
    27.     0x00000001417F0664 (Unity) WinMain
    28.     0x0000000141AD38E4 (Unity) strnlen
    29.     0x00007FFD4A4A3034 (KERNEL32) BaseThreadInitThunk
    30.     0x00007FFD4CF21431 (ntdll) RtlUserThreadStart
    and:

    Code (CSharp):
    1.     var al = FindObjectOfType<AudioListener>();
    2.     Debug.Log("**** " + al + " : " + al.name);
    which returns:

    Code (CSharp):
    1. **** Head Target (UnityEngine.AudioListener) : Head Target
    2.     0x000000014179D92B (Unity) StackWalker::GetCurrentCallstack
    3.     0x000000014179F5DF (Unity) StackWalker::ShowCallstack
    4.     0x00000001417796A0 (Unity) GetStacktrace
    5.     0x0000000140D3F23B (Unity) DebugStringToFile
    6.     0x0000000140D3FA1C (Unity) DebugStringToFile
    7.     0x00000001413FE562 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    8.     0x000000003C8F2F5B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
    9.     0x000000003C8F2E44 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    10.     0x000000003C8F27D5 (Mono JIT Code) [Logger.cs:41] UnityEngine.Logger:Log (UnityEngine.LogType,object)
    11.     0x000000003C8F2016 (Mono JIT Code) [DebugBindings.gen.cs:103] UnityEngine.Debug:Log (object)
    12.     0x00000000137EDBF2 (Mono JIT Code) [PUNManagerStarter.cs:60] PUNManagerStarter:Update ()
    13.     0x00000000008C7392 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    14.     0x00007FFD0CA55703 (mono) [mini.c:4937] mono_jit_runtime_invoke
    15.     0x00007FFD0C9A8425 (mono) [object.c:2623] mono_runtime_invoke
    16.     0x00000001410657E5 (Unity) scripting_method_invoke
    17.     0x000000014105B461 (Unity) ScriptingInvocation::Invoke
    18.     0x0000000141498F5B (Unity) MonoBehaviour::CallMethodIfAvailable
    19.     0x000000014149D05F (Unity) MonoBehaviour::CallUpdateMethod
    20.     0x0000000140AC4A86 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
    21.     0x0000000140AC567F (Unity) BehaviourManager::Update
    22.     0x0000000140D74BC7 (Unity) PlayerLoop
    23.     0x000000014171983E (Unity) Application::UpdateScene
    24.     0x000000014171B00F (Unity) Application::UpdateSceneIfNeeded
    25.     0x000000014172373A (Unity) Application::TickTimer
    26.     0x00000001417EEA1C (Unity) CrashCallback
    27.     0x00000001417F0664 (Unity) WinMain
    28.     0x0000000141AD38E4 (Unity) strnlen
    29.     0x00007FFD4A4A3034 (KERNEL32) BaseThreadInitThunk
    30.     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
    Code (CSharp):
    1. var cam = FindObjectOfType<Camera>();
    I get:
    Code (CSharp):
    1. Headcam (UnityEngine.Camera) : Headcam
     
    Last edited: Jul 26, 2018
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    This answer on another thread tells you how to handle this.
     
  3. Towerss

    Towerss

    Joined:
    Feb 17, 2018
    Posts:
    8
    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.
     
  4. Towerss

    Towerss

    Joined:
    Feb 17, 2018
    Posts:
    8
    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:

    Code (CSharp):
    1.  
    2.     void Update()
    3.     {
    4.         if (Input.GetKeyDown(KeyCode.Space))
    5.         {
    6.             GameObject[] foundObjects = FindObjectsOfType<GameObject>();
    7.             Debug.Log("**** " + foundObjects + " : " + foundObjects.Length);
    8.             var count = 0;
    9.             if (foundObjects != null)
    10.             {
    11.                 foreach (GameObject foundObject in foundObjects)
    12.                 {
    13.                     count++;
    14.                     if (foundObject.hideFlags == HideFlags.HideInHierarchy || foundObject.hideFlags == HideFlags.HideInInspector)
    15.                     {
    16.                         foundObject.hideFlags = HideFlags.None;
    17.                         Debug.Log("**** foundObject: " + foundObject + " : foundObject Name: " + foundObject.name + " - Count: " + count);
    18.                     }
    19.                 }
    20.             }
    21.         }
    22.     }

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