This issue shows up when I'm testing my code as shown below, and it only happens when CustomSounds is enabled:
//_instrClip is the new clip I want to assign to the audioSource
Instruments4MusicPlugin.AddLog($"{audioSource.GetInstanceID()} {audioSource.clip} to {_instrClip.name}.");
audioSource.Play();
Instruments4MusicPlugin.AddLog($"{audioSource.GetInstanceID()} {audioSource.clip} to {_instrClip.name}.");
My function is to assign an audioClip to an audioSourceThis first clip to be assigned is ShipAlarmHornConstant, I replaced this clip using CustomSounds.
[Info :Instruments4Music] -181124 ShipAlarmHornConstant (UnityEngine.AudioClip) to ShipAlarmHornConstant.
[Info :Instruments4Music] -181124 ShipAlarmHornConstant (UnityEngine.AudioClip) to ShipAlarmHornConstant.
For the second clip I didn't use CustomSounds on it.
The new audioSource and the new audioClip are unrelated to the old ones. (But they are on the same gameObject)
Before the audio is played audioSource.Play();, the AudioClip on the AudioSource is AirHorn1.
However, it changed to ShipAlarmHornConstant immediately when the AudioSource plays.
[Info :Instruments4Music] destroy -181124. **Here the old AudioSource is destroyed**
[Info :Instruments4Music] -198614 AirHorn1 (UnityEngine.AudioClip) to AirHorn1.
[Info :Instruments4Music] -198614 ShipAlarmHornConstant (UnityEngine.AudioClip) to AirHorn1.
I have been working on debugging this for 3 hrs. I still have no clue about this.
This is what I expected, and it works well when CustomSounds is disabled.
[Info :Instruments4Music] -28438 AirHorn1 (UnityEngine.AudioClip) to AirHorn1.
[Info :Instruments4Music] -28438 AirHorn1 (UnityEngine.AudioClip) to AirHorn1.
I rolled back my code and discovered that the issue arose from modifying two AudioSource components placed on the same GameObject (the Player). Separating them to different GameObjects works around the problem.
This issue shows up when I'm testing my code as shown below, and it only happens when CustomSounds is enabled:
My function is to assign an audioClip to an audioSource This first clip to be assigned is ShipAlarmHornConstant, I replaced this clip using CustomSounds.
For the second clip I didn't use CustomSounds on it. The new audioSource and the new audioClip are unrelated to the old ones. (But they are on the same gameObject) Before the audio is played
audioSource.Play();
, the AudioClip on the AudioSource is AirHorn1. However, it changed to ShipAlarmHornConstant immediately when the AudioSource plays.I have been working on debugging this for 3 hrs. I still have no clue about this.
This is what I expected, and it works well when CustomSounds is disabled.