Sequencer: Mute tracks at runtime from C++

Hello, to disable sequencer tracks at runtime I used

  • UMovieSceneTrack::SetEvalDisabled(bool)
  • ULevelSequence::MarkAsChanged()
  • MovieSceneCompiledDataManager::GetPrecompiledData()->Compile(ULevelSequence*)
// You first have to set the unwanted track as disabled via 
void YourDisableTrackFunction(UMovieSceneTrack* MovieSceneTrack, bool Value)
{
	if (MovieSceneTrack)
	{
		MovieSceneTrack->SetEvalDisabled(Value);
	}
}


// Then notify the sequencer that the tracks have been modified using MarkAsChanged and UMovieSceneCompiledDataManager::GetPrecompiledData()->Compile.
void YourMarkAsChangedFunction(ULevelSequence* Sequence)
{
	if (Sequence)
	{
		Sequence->MarkAsChanged();
		if (UMovieSceneCompiledDataManager::GetPrecompiledData())
		{
			UMovieSceneCompiledDataManager::GetPrecompiledData()->Compile(Sequence);
		}
	}
}

Use this if you want to notify multiple modifications at one time during runtime.

There is another option to set the concerned track as volatile which if I understood well, doesn’t need to markaschanged and compile the sequencer when you modify the tracks at runtime.
I didn’t tried it.

// this needs to be done in the editor on the concerned tracks
void YourSetLevelSequenceAsVolatileFunction(ULevelSequence* Sequence)
{
	if (Sequence)
	{
		Sequence->SetSequenceFlags(Sequence->GetFlags() | EMovieSceneSequenceFlags::Volatile);
		Sequence->MarkAsChanged();
		if (UMovieSceneCompiledDataManager::GetPrecompiledData())
		{		UMovieSceneCompiledDataManager::GetPrecompiledData()->Compile(Sequence);
		}
	}
}

Ps: Do not forget to reenable the tracks if you need them later on .

5 Likes