Hello.
I am creating ULevelSequencePlayer
and ALevelSequenceActor
to play my sequence from C++.
ALevelSequenceActor * currentLevelSequenceActor = nullptr;
ULevelSequencePlayer * currentLevelSequencePlayer = nullptr;
currentLevelSequencePlayer = ULevelSequencePlayer::CreateLevelSequencePlayer(GetWorld(), levelSequence, FMovieSceneSequencePlaybackSettings(), currentLevelSequenceActor);
currentLevelSequencePlayer->Play();
After I am done with it, how should I remove those objects / inform GC that I no longer need them?
Hi,
I found this question because I use level sequences too and I was wondering about the same thing.
By reading the code of ULevelSequencePlayer::CreateLevelSequencePlayer, I’ve had some answers :
- The actor stored in the OutActor pointer parameter is internally created using the World you pass to the function using a plain World->SpawnActor. So my guess is when you want to get rid of it, just call OutActor->Destroy(). But given the World holds a list of actors references, if you can wait until world is destroyed and automatically cleans all actors, you may not bother.
- The returned ULevelSequencePlayer* is actually a member of OutActor, so in theory it shouldn’t outlive it. Note that this pointer is allocated using a plain NewObject call, and I can’t seem to find any ALevelSequenceActor destructor responsible of deleting it. So I think we’re entirely relying on the garbage collector here.
I don’t know much about UE garbage collector so I could be wrong.
To recap:
- use OutActor->Destroy() if you want to kill both, and be sure to never use the sequence player after that
- you can just let them drop out of scope if you can afford waiting for the world destruction. They will probably be garbage collected.
Hi,
i`m trying to create sequence by code.may i ask how you load or create levelSequence in code?
ULevelSequence* OpenLvlSequence = LoadObject<ULevelSequence>(NULL,
TEXT("LevelSequence'/Game/Sequence/OpenningLevelSequence.OpenningLevelSequence'"));
if (OpenLvlSequence)
{
ALevelSequenceActor * CurLvlSequenceActor = nullptr;
ULevelSequencePlayer * CurLvlSequencePlayer = nullptr;
CurLvlSequencePlayer = ULevelSequencePlayer::CreateLevelSequencePlayer(GetWorld(),
OpenLvlSequence, FMovieSceneSequencePlaybackSettings(), CurLvlSequenceActor);
if (CurLvlSequencePlayer)
{
CurLvlSequencePlayer->Play();
}
}
when i use this way loaded level sequence,there is a link error as “Error LNK2019: Unparsable external symbol “_declspec (dllimport) public: void _cdecl UMovieSceneSequencePlayer:: Play (void)””