Hi,
I need to keep the instance of my gameMode between levels.
After a bit of research i use PrepareMapChange/CommitMapChange, it works as intended but when changing levels,
the actors of the previous one are not garbage collected.
So all the previous actors, light, bsp are still up.
Should i destroy them manually ?
this is the code i got now.
The event that change level, when enterring in a “Hole”
void ■■■■■::OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult) {
OurParticleSystem->Activate(false);
AudioComp->Activate(false);
if(OtherActor->GetClass()->IsChildOf(ABall::StaticClass())){
((ATwitchTestGameMode*)GetWorld()->GetAuthGameMode())->destroyActors();
((ATwitchTestGameMode*)GetWorld()->GetAuthGameMode())->loadMaps();
}
}
in ATwitchTestGameMode i have 2 method: destoryActors and loadmaps
void ATwitchTestGameMode::destroyActors()
{
for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
AActor *actor = *ActorItr;
UE_LOG(LogTemp, Warning, TEXT("Actors: %s"),*(actor->GetName()));
//actor->Destroy();
}
}
void ATwitchTestGameMode::loadMaps()
{
TArray<FName> loader;
incrementLevel();
loader.Add(FName(*levels[level]));
GetWorld()->PrepareMapChange(loader);
displayWinningScreen();
FTimerHandle timer;
GetWorld()->GetTimerManager().SetTimer(timer, this, &ATwitchTestGameMode::resetLevel, timeScreen, false);
//if (GetWorld()->IsMapChangeReady) {
GetWorld()->CommitMapChange();
}
Then i have a bit of code in the PostCommitMapChange() callback method
I don’t know why the actors are not deleted when swapping levels.
I don’t know if GetWorld()->CommitMapChange(); is blocking untill GetWorld()->IsMapChangeReady return true.
If not should i block the execution and avoiding a while loop ?
Do you think deleted all the actors before swapping is the good aproach and avoiding the gamemode?
Thanks