Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

HMD's rotation is ignored, on a playing AudioSource, once another AudioSource stops playing #54

Open
masammut opened this issue Oct 12, 2018 · 26 comments

Comments

@masammut
Copy link

I'm not sure if this is a Unity, a Resonance Audio bug or if I'm doing something wrong, but on Unity >= 2018.2.2f1 the HMD's rotation (possibly position too, but untested) is ignored on a playing AudioSource, once another AudioSource stops playing (only tested with 2 AudioSources).

This works fine in:

  • Unity 2017.3.1f1
  • Unity 2018.1.0f2

Seems to be broken in:

  • Unity 2018.2.2f1 to 2018.3.0b5

(Note: In this example I'm using SteamVR version 1.2.3 because version 2 has issue with 2018.3 at the moment, but I've managed to recreate the same issue using SteamVR 2.0.1 (see notes below))

Steps to recreate:

  1. Start with a new project
  2. Assets / Import Package / Custom Package -> SteamVR.Plugin.unitypackage (from: https://github.com/ValveSoftware/steamvr_unity_plugin/releases/tag/1.2.3)
  3. Assets / Import Package / Custom Package -> ResonanceAudioForUnity_1.2.1.unitypackage (from: https://github.com/resonance-audio/resonance-audio-unity-sdk/releases)
  4. If using >= Unity 2018.3 (beta at the moment) add OpenVR version 1.0.2 using Window / Package Manager
  5. In the Edit > Project Settings > Audio (or equivalent in Unity >= 2018.3)
    1. Select Resonance Audio as the Spatializer Plugin
    2. Select Resonance Audio as the Ambisonic Decoder Plugin.
  6. Create a new scene
  7. Disable Main Camera
  8. Add SteamVR "[CameraRig]" Prefab
  9. (Add a floor plane if you want)
  10. Create an empty GameObject at 0,0,0 and add the script attached below
  11. Attach a 5 second clip to both ClipLooped and ClipPlayedOnce (clips can be same or different, but make sure ClipPlayedOnce is around 5 seconds to have enough testing time)
  12. Save scene
  13. Press play
  14. While both clips are played (ie 1st iteration of the loop) rotate the HMD left / right and hear the audio panning depending on the HMD's rotation
  15. Then rotate the HMD so that the audio comes from the left ear and wait till ClipPlayedOnce finishes
  16. Rotate the HMD and observer that the audio from ClipLooped does not pan left / right anymore but remains at the same place it was when ClipPlayedOnce finished playing

Notes:

  1. If "audioSource2.Play();" is commented out, then ClipLooped seems to come from the center and the HMD's rotation is ignored too.
  2. If the looping is inverted (ie "audioSource1.loop = false;", "audioSource2.loop = true;" and "audioSource2.Play();" uncommented) then it works fine (note: volume will be lower because of distance / occlusion)
  3. Also tested on Unity 2018.2.2f1 with SteamVR 2.0.1 (and the following change "var ears = GameObject.Find("Camera");") and the same problem was observer
using UnityEngine;

public class Sample : MonoBehaviour
{

    public AudioClip ClipLooped;
    public AudioClip ClipPlayedOnce;

    void Awake()
    {
        var ears = GameObject.Find("Camera (ears)");
        ears.AddComponent<ResonanceAudioListener>();

        var cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube1.transform.position = new Vector3(0f, 1.5f, 3f);

        var cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube2.transform.position = new Vector3(0f, 1.5f, 4f);

        var audioSource1 = CreateAudioSources(cube1);
        audioSource1.spatialBlend = 1f; // 1 -> full 3D.
        audioSource1.spatialize = true;
        audioSource1.spatializePostEffects = true;  
        audioSource1.clip = ClipLooped;
        audioSource1.loop = true;
        audioSource1.Play();           
        
        var audioSource2 = CreateAudioSources(cube2);
        audioSource2.spatialBlend = 1f; // 1 -> full 3D.
        audioSource2.spatialize = true;
        audioSource2.spatializePostEffects = true;  
        audioSource2.clip = ClipPlayedOnce;
        audioSource2.loop = false;
        audioSource2.Play();
    }

    private AudioSource CreateAudioSources(GameObject go)
	{
        var audioSource = go.AddComponent<AudioSource>();
        audioSource.outputAudioMixerGroup = ResonanceAudio.MixerGroup;

        var resonanceAudioSource = go.AddComponent<ResonanceAudioSource>();
        resonanceAudioSource.occlusionEnabled = true;

        return audioSource; 
    }

}
@masammut masammut changed the title HMD's rotation is ignored on a playing AudioSource once another AudioSource stops playing HMD's rotation is ignored, on a playing AudioSource, once another AudioSource stops playing Oct 12, 2018
@masammut
Copy link
Author

masammut commented Oct 12, 2018

Note: I've noticed that after step 16, by manually toggling (in Unity's inspector) the Output (outputAudioMixerGroup) of the audioSource1 to None and then back to ResonanceAudioMixer/Master, the playing clip for that source starts tracking the HMD's rotation once again.

@andybak
Copy link

andybak commented Oct 25, 2018

I wonder if this explains the weird elusive problem I had where spatialization was correct in a minimal test scene but seemed to reverse left and right in anything complex.

@Back2RL
Copy link

Back2RL commented Oct 30, 2018

I am having the same problem with Unity 2018.2f12. I noticed that the audio positions/spatialization updated only on the first frame when I called AudioSource. play() after any AudioSource finished playing. I hope this can be sorted out soon.

@andybak
Copy link

andybak commented Oct 31, 2018

Could we get any acknowledgement about this issue from the devs? In general it's beginning to seem like this is an abandoned project - which is a shame.

@CrazyOldMaurice
Copy link

Hi folks. Can you please submit a bug using the bug reporter tool and include a minimum repro project so that I can see the exact setup? Please send the bug number/title here once you get the reply email so I can grab it and start working on it?

@andybak
Copy link

andybak commented Nov 14, 2018

@CrazyOldMaurice I had a go at creating a minimal test case but it wasn't clear what the trigger was. It happened in a complex scene and didn't happen in a simple scene. I ran out of time to pin it down (switched to the Oculus Spatializer instead).

If it helped it seemed to happen irrespective of Unity version (2018.x) and I was using the latest released version of Resonance.

My tests were before I saw this ticket so I didn't think to check for this precise cause but the symptom was that left and right were reversed in spatialized sound.

@masammut
Copy link
Author

@CrazyOldMaurice where can we find the bug reporter tool you mentioned please? Or do you mean opening another issue on Github?

@CrazyOldMaurice
Copy link

@masammut the Unity bug reporter is found under the editors Help tab -> Report a bug...
Please include in the writeup what VR device you are using.

@andybak a repro project from you might help me to figure out what's happening more quickly, please make a separate bug report for your issue in case it turns out to be something different from masammut's.

Thank you both for your assistance and patience.

@CrazyOldMaurice
Copy link

Did either of you use the bug reporter to file a bug and upload a repro project for me to look at?

@andybak
Copy link

andybak commented Nov 20, 2018

@CrazyOldMaurice I'm afraid a repo project is really not feasible without a ton of work which I am unlikely to have the time for now that I got around the issue (sadly by ditching Resonance)

@CrazyOldMaurice
Copy link

CrazyOldMaurice commented Nov 20, 2018 via email

@CrazyOldMaurice
Copy link

So, good news. I got pointed to a non-VR forum post that I sounded suspiciously like this one. I was able to make a good repro project locally and get it to one of our devs to investigate further. I think he may have something figured out, but I'm not sure if it's something that should fixed in Unity code, or if it is something that needs fixed in the plugin. Will update as I can if there's a fix and/or workaround.

@Goyoman
Copy link

Goyoman commented Dec 3, 2018

  • WORKAROUND -

Checkmark "Play in Awake" and use enable = true/false instead.

@bcjordan
Copy link

bcjordan commented Feb 6, 2019

Any update on what in particular the issue is/was and how it presents itself? & if using Unity 2017.3.1f1 / 2018.1.0f2 protects against it?

@bcjordan
Copy link

bcjordan commented Mar 1, 2019

Workaround is to toggle active/inactive on the GameObject or enabled/disabled on the AudioSource component after any audio source ends, see code snippet here: #55 (comment)

@purplejamltd
Copy link

Hey, if my audiosource is set to 'Play On Awake' using the code snippet restarts the audio, how would I get around this? I'm sure it's a very simple answer but I'm very new to coding.

All the best
Harry

@hectorC
Copy link

hectorC commented Mar 27, 2019

Any news on the fix? The enable/disable workaround is not practical for a large complex project. We are about to decide to not use Resonance but I was wondering if any progress has been made on this issue? Thanks!

@RodjaAlbus
Copy link

Hi. I discovered that if you put all the audiomixers´ "Update mode" on Unscaled time instead of normal it works.

@purplejamltd
Copy link

How does one do that? Bit of a newbie here. Though if you've solved this you're wonderful.

All the best
Harry

@RodjaAlbus
Copy link

Hi. It does not solve it completely. Sometimes I still get the error. :( You open the audimixer panel, select the existing audiomixer, or the one that you created, and on the inspector you see the "Update mode" drop down menu,

@chrisofthelane
Copy link

Quasi-good news. I tried a basic test scene with two short audio sources repeating starting/stopping on timers, and one continuous looping source. This repros the bug 100% reliably in the original reported case. I tried the same scene across three Unity versions.
Bug exists in 2018.2.20f1
Bug exists in 2018.4.1f1
Bug does NOT exist in 2019.1.0f2

Looks like an upgrade to 2019 might fix this if you're having this bug.

@CrazyOldMaurice
Copy link

So, good news is that we've implemented a fix in 2019.1+. On previous versions the work around will be needed. On a plus side the workaround is fairly simple. On your audio sources be sure to call source.SetSpatialize(false) after the sound is done playing and be sure to call source.SetSpatialize(true) before you play another sound through that audio source. The issue is that the Resonance may get it's audio listener coordinates from a stale audio source. So something like MySpatializedAudioSource.SetSpatialize(false) when it's finished playing a sound.

@purplejamltd
Copy link

The issue still seems to be there in 2019.1.5 for me. Anyone else?

@chrisofthelane
Copy link

Yeah, actually, still having intermittent issues in 2019.1.5f1 here. Definitely way better, but not 100%. :(

@CrazyOldMaurice
Copy link

@purplejamltd Would you have a repro project/steps if you're catching it frequently? My testing still looks good for this issue.

@AaronVictoria
Copy link

I've worked a few programming contracts on projects that utilize Resonance Audio, a few even brought me onboard specifically to help them with this particular issue. In every case, I've resolved the issue creating a unique child GameObject of the Audio Listener. This is a practice that I utilize in every project that I work on, and I do likewise with the Audio Source elements. I simply make a child GameObject at the origin or the camera (0,0,0), add the Resonance Audio Listener component to it, and I have Resonance Audio Source objects applied individual GameObjects as well. If I'm spawning Audio Source components on dynamically instantiated GameObjects, I ensure that those are spawned free of any extra components or children.

You don't want these objects colliding with other components or for the component prioritizing to be compromised in any way, or it simply won't work. I've implemented this process since I started used using over 6 years ago, and still do it now. It has also resolved my clients' issues from Unity version 2018.1 to 2019.2. I haven't done any work, personal or professional, in 2019.3 yet, but will confirm once I have.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests