Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the wrong AudioClip #20

Open
BoredBean opened this issue Mar 15, 2024 · 1 comment
Open

Replace the wrong AudioClip #20

BoredBean opened this issue Mar 15, 2024 · 1 comment

Comments

@BoredBean
Copy link

BoredBean commented Mar 15, 2024

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 audioSource
This 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.
@BoredBean
Copy link
Author

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.

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

No branches or pull requests

1 participant