Search Issue Tracker

By Design

Votes

0

Found in

2021.3.16f1

2022.2.2f1

2023.1.0a25

2023.2.0a2

Issue ID

UUM-28014

Regression

No

Reference to audio clip is lost when Editor loses focus

--

-

Reproduction steps:

1. Open the “CatsronautEdited” project
2. Open the “Assets/GAME/Scenes/New Scene.unity” Scene
3. In the Hierarchy Window select “GameObject (1)” GameObject’s child “GameObject” GameObject
4. Enter the Play Mode
5. Observe that an audio clip is assigned in the “AudioClip“ property of the “Audio Source” Component
6. Select another application or switch windows
7. Return to the Editor

Expected results: The audio clip is still playing
Actual results: Reference in the “Audio Clip” property is lost

Reproducible with: 2021.3.16f1, 2022.2.2f1, 2023.1.0a25

, 2023.2.0a2
Could not test with: 2020.3.44f1 (error CS8124: Tuple must contain at least two elements, error CS1526: A new expression requires (), [], or {} after type)

Reproduced on: Intel MacOS 13.1

Note: The audio clip stops playing when the Editor loses focus, but the reference disappears only when returning to Editor

  1. Resolution Note:

    Looking into the repro project I can see that MusicManager.Update is setting the clip to null on line 100, so the clip being null is expected, and is down to the user supplied script.



    I would guess the misunderstanding here is the behavior of AudioSource.isPlaying, which is being used as a way to tell if a clip has stopped. Under normal circumstances this will work - however when unity is put into background the audio system will suspend, causing isPlaying to return false. isPlaying works much more like “is sound coming out of the speakers right now”, which is not the case when the system is suspended. On this point we should update the documentation to make this more clear.

    
I can see two solutions here, the first is pretty easy. If you are happy to keep the music playing whilst unity is not in focus, set run in background in Edit > Project Settings -> Player>Resolution->Run In Background to true.

    The other solution to be to use AudioSource.time with AudioClip.Length to check if the source has actually finished playing, and do the source swapping logic when that is the case.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.