tobiasw
New Member
Posts: 10
Posts: 10
|
Post by tobiasw on Sept 13, 2016 15:40:08 GMT
Hello,
I have a sound clip whose volume I want to later adjust in each Update() call. I don't know the initial volume, so I want to set it to 0 initially - but if I call
soundEffect = MasterAudio.PlaySound3DAtTransform(soundEffectName, transform, 0f);
the sound effect stays silent even when I call
soundEffect.ActingVariation.AdjustVolume(volume);
later.
Is there any way to start it with 0, but still keep it adjustable?
Cheers, Tobias
|
|
|
Post by DarkTonic Dev on Sept 13, 2016 20:01:58 GMT
Actually no, you can't do it that way. What you can do is set the volume to zero right after playing it at a non-zero volume. You won't be able to hear it before you set it to zero so it should be fine.
|
|
tobiasw
New Member
Posts: 10
Posts: 10
|
Post by tobiasw on Sept 13, 2016 22:48:56 GMT
I can't test this right now, but I think I remember that calling "soundEffect.ActingVariation.AdjustVolume(0f);" right after calling PlaySound3DAtTransform() led to a null pointer exception. If this doesn't ring any bells, I'll check it and report back on Thursday!
|
|
|
Post by DarkTonic Dev on Sept 13, 2016 22:58:25 GMT
No that definitely doesn't ring any bells...
However you should always check that ActingVariation is not null before using it in case nothing was played (voice count exceeded etc).
|
|
tobiasw
New Member
Posts: 10
Posts: 10
|
Post by tobiasw on Sept 15, 2016 11:40:33 GMT
I can't reproduce it anymore, but AdjustVolume doesn't seem to work if called right after PlaySound3DAtTransform. The sound still plays at full volume:
var result = MasterAudio.PlaySound3DAtTransform("Wheel", transform, 1f); result.ActingVariation.AdjustVolume(0f);
Testing further, this seems to work:
var result = MasterAudio.PlaySound3DAtTransform("Wheel", transform, 1f); result.ActingVariation.VarAudio.volume = 0f;
Is that the best way to do it? Which of these will I have to check for null?
|
|
|
Post by DarkTonic Dev on Sept 15, 2016 20:05:48 GMT
You need to check that result.ActingVariation is not null. If nothing was played it will be null.
Anyway, you found a bug with AdjustVolume. Fix it by changing the first if statement in it as shown below (this is in SoundGroupVariation.cs)
public void AdjustVolume(float volumePercentage) { if (!_playSndParam.IsPlaying) { return; }
|
|
|
Post by DarkTonic Dev on Sept 15, 2016 20:19:42 GMT
By the way, I've also fixed the code so you can use the code in your original post and it will work, for the next update.
|
|
tobiasw
New Member
Posts: 10
Posts: 10
|
Post by tobiasw on Sept 16, 2016 10:43:53 GMT
Thanks a lot for your help!
|
|
|
Post by DarkTonic Dev on Sept 16, 2016 15:55:26 GMT
No problem!
|
|