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.
I find this post:
but nothing to do with actors still present
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?
when i make the list of the AActors present i got this:
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: PlayerController_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Ball1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: DefaultPhysicsVolume_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: GlobalPostProcessVolume
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: InstancedFoliageActor_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Wall
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Wall2
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Wall3
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Wall4
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Starter_Music_Cue_4
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: CameraActor_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: CameraActor_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: PlayerCameraManager_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: HUD_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: AtmosphericFog_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: GameNetworkManager_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: GameSession_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: GameState_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: PlayerState_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: SkyLight_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: WorldSettings_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: PlayerStart
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Minimal_Default_C_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: LightSource
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: AbstractNavData-Default
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: ParticleEventManager_0
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: SphereReflectionCapture10
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: SphereReflectionCapture_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: ActorTwitchEventListener_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: CameraDirector_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: Hole_1
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: TunnelEffect
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: TunnelEffect2
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: TunnelEffect3
[2016.09.21-06.22.52:642][442]LogTemp:Warning: Actors: BP_Sky_Sphere_C_2
What actors should i avoid to destroy.
It causes my game to crash.
Thanks