Hello,
I am experiencing the following issue in UE4.9.2:
- Create a SoundCue that contains a “Branch” node
- Add an AudioComponent to the player pawn that plays the given sound Cue.
- At runtime (say on player input), make a change to the Parameter that is used by the Branch node (using
UAudioComponent::SetBoolParameter
) - Note that the first time the change is made, the sound being played restarts from the beginning
- Note that the second time the change is made, the sound being plays stops playing
- Note that subsequent calls to the function have no effect, and that calling
UAudioComponent::IsPlaying
returns false.
Expected result: Calling UAudioComponent::SetBoolParameter does not restart or stop the playing audio.
This appears to be caused by the change in NodeWaveInstanceHash
in the function USoundNodeBranch::ParseNodes
:
void USoundNodeBranch::ParseNodes( FAudioDevice* AudioDevice, const UPTRINT NodeWaveInstanceHash, FActiveSound& ActiveSound, const FSoundParseParameters& ParseParams, TArray<FWaveInstance*>& WaveInstances )
{
BranchPurpose BranchToUse = BranchPurpose::ParameterUnset;
bool bParamValue = false;
if (ActiveSound.GetBoolParameter( BoolParameterName, bParamValue ))
{
BranchToUse = (bParamValue ? BranchPurpose::ParameterTrue : BranchPurpose::ParameterFalse);
}
const int32 ChildNodeIndex = (int32)BranchToUse;
if (ChildNodeIndex < ChildNodes.Num() && ChildNodes[ChildNodeIndex])
{
ChildNodes[ChildNodeIndex]->ParseNodes(AudioDevice, GetNodeWaveInstanceHash(NodeWaveInstanceHash, ChildNodes[ChildNodeIndex], ChildNodeIndex), ActiveSound, ParseParams, WaveInstances);
}
}
When the bool parameter changes, the BranchToUse
value is different. This in turn causes a different ChildNodeIndex
to be set, and so different parameters are passed into USoundNode::GetNodeWaveInstanceHash
, resulting in a different NodeWaveInstanceHash
after the parameter is set, compared to before. Then, in USoundWave::Parse
, the call to FActiveSound::FindWaveInstance
returns NULL
, which causes a new WaveInstance
to be created and started, via USoundWave::HandleStart
. This is the cause of the audio restarting (step 4)
When the bool parameter changes back to its original value, the NodeWaveInstanceHash
returns to its original value also. Then, the call to FActiveSound::FindWaveInstance
finds the WaveInstance
that was playing before the first parameter change. This WaveInstance
, however, has bIsFinished
already set to true, which causes the Audio system to flag that the audio finished playing (step 5). This in turn is propegated to the AudioComponent’s bIsActive
flag, and thus IsPlaying()
returns false (step 6).
Is this the expected behaviour? Are changes to audio parameters at runtime supported?
Thanks,
,