Is there a way to trigger a level sequence in C++?

I want to be able to play my level sequence in code, so I can trigger it with a method whenever I need it. However I can’t find how to reference a level sequence in C++ and how to play it. How would I go about doing this?
Thank you in advance.

You should be able to create a level sequence player, LevelSequencePlayer.h:

static ULevelSequencePlayer* CreateLevelSequencePlayer(UObject* WorldContextObject, ULevelSequence* LevelSequence, FMovieSceneSequencePlaybackSettings Settings);

and pass it the ULevelSequence you want to play. You might get the ULevelSequence like this:

FStringAssetReference SequenceName("/Game/NewLevelSequence.NewLevelSequence");
ULevelSequence* Asset = Cast<ULevelSequence>(SequenceName.TryLoad());

Then, call Play() on the returned ULevelSequencePlayer.

Thank you very much!

Max.Chen , how do I use this function to create level sequence player , im new to c++
Error MyPlayerController.cpp.obj : error LNK2019: unresolved external symbol “public: static class ULevelSequencePlayer * __cdecl AMyPlayerController::CreateLevelSequencePlayer(class UObject *,class ULevelSequence *,struct FMovieSceneSequencePlaybackSettings)” (?CreateLevelSequencePlayer@AMyPlayerController@@SAPEAVULevelSequencePlay
er@@PEAVUObject@@PEAVULevelSequence@@UFMovieSceneSequencePlaybackSettings@@@Z) referenced in function “public: void __cdecl AMyPlayerController::CallTimer(void)” (?CallTimer@AMyPlayerController@@QEAAXXZ)

Sorry for the slow response. Looks like you need to add MovieScene and LevelSequence to the public dependency modules.

Take a look at this post: Linker error (LNK2019) when trying to play a Level Sequence

Trying to get around this too… Any working examples around maybe?

This is what I tried but no luck (camera swap and fade-in works fine but no sequence is played nor any logs are printed about failures):

Constructor:

    	// Init Sequence Player
    	CinematicSequencePlayer = ObjectInitializer.CreateDefaultSubobject<ULevelSequencePlayer>(this, LevelScriptStatics::CinematicSequencePlayername);
    
    	// Init waking up cinematic sequence
    	static ConstructorHelpers::FObjectFinder<ULevelSequence> MySequenceTemplate(TEXT("LevelSequence'/Game/Sequences/Cinematics/MySequence_LS'"));
    	if (MySequenceTemplate.Succeeded()) MySequence = MySequenceTemplate.Object;

Some other function further down the code:

    		if (ourPC->GetViewTarget() == CinematicCamera && ourPC->PlayerCameraManagerClass != nullptr)
    		{
    			//Fade from black
    			ourPC->PlayerCameraManager->StartCameraFade(1.f, 0.f, 5, FColor::Black, true);
    
    			//Sequence Settings
    			if (CinematicSequencePlayer && MySequence)
    			{
    				CinematicSequencePlayer->CreateLevelSequencePlayer(GetWorld(), MySequence, FMovieSceneSequencePlaybackSettings());
    				if (CinematicSequencePlayer->GetSequence())
    				{
    					CinematicSequencePlayer->Play();
    					CinematicLength = CinematicSequencePlayer->GetLength();
    				}
    			}
    		}

May I add an additional response here? It depends whether you want a full C++ create-and-play solution or, if you’re like me, you just want to trigger a sequence that’s already in your scene. I have a single FadeIn / FadeOut sequence for entering / leaving my level that’s dropped on the map. I simply iterate the sequencer actors, and the player is already a member function of it.

for (TActorIterator<ALevelSequenceActor> it(GetWorld()); it; ++it)
{
	ALevelSequenceActor *lsa = *it;

	if (lsa->GetName() == TEXT("FadeOut"))
		lsa->SequencePlayer->Play();
}

I finally got it working.

.h

	//The sequence player
	UPROPERTY()
		ULevelSequencePlayer* SequencePlayer;

	// Sequence Assets
	UPROPERTY(EditAnywhere)
		ULevelSequence* SequenceAsset;

.cpp

// Setup the sequence player
if (SequenceAsset && SequencePlayer == nullptr)
    				SequencePlayer = ULevelSequencePlayer::CreateLevelSequencePlayer(GetWorld(), SequenceAsset, FMovieSceneSequencePlaybackSettings());
    
    			//Sequence Play
    			if (SequencePlayer)
    			{
    				SequencePlayer->Play();
    			}
    		}

I’m trying to use this code as a guide to get my level sequence playing but visual studio says ULevelSequencePlayer, and ULevelSequence, are undefined. Is there a specific header file I need to include in order to use these types? I can’t seem to find that anywhere. Thanks.

I’m currently away from the office but if I recall correctly #include “LevelSequencePlayer.h” should do the job.

Hi,
how to render a movie (or image sequence) with specific frame rate and output format using the same level sequencer triggered from code?

i include :

#include “Runtime/LevelSequence/Public/LevelSequence.h”

#include “Runtime/LevelSequence/Public/LevelSequencePlayer.h”

but I can’t access to their function or variables. anyone did have the same experience?
its build with no error but when I want to access, for example, CreateLevelSequencePlayer() I couldn’t.

im very grateful if anyone can help, im stuck at this point.

Have you tried to add it to the UnrealBuild.cs? In order for me to access some functions I had to have the following dependency modules:

PublicDependencyModuleNames.AddRange(new string[] {
“…”,
“LevelSequence”,
“MovieScene”
});

Maybe you only need LevelSequence, maybe both, maybe you already added it, but eitherway here goes :slight_smile:

You have to add it to the c++ directories in the project settings in order for visual studio to access the variables and functions.

Tutorial Spanish.

Github source code.

Discussion in another entry I made.