Knowing When a Level is about to be unstreamed, but still accessing its members before it fully unstreamed

Dear Friends at Epic,

I extended LevelScriptActor,

and I have been happily using and setting custom values for my levels which are re-parented to use this new ScriptActor

I am doing this to facilitate the tracking of level streaming.

I have an issue though.

My extended level blueprint has variables with important data that I want to save

  • when the level is about to be unstreamed
  • before it is deleted, so that its member values are still filled with data

I’ve tried using different events in C++, and it is not working


In the code below, the name always shows up as none, and other member var data is also now invalid
how can I get the member var data after unstreaming begins, before the level is deleted and member var data lost?

//LevelScriptActor.h 		BeginDestroy()
void AVictoryLevelScriptActor::BeginDestroy()
{
	Super::BeginDestroy();
	//~~~~~~~~~~
	
	UE_LOG(Victory,Error,TEXT("STREAMING LEVEL UNLOADED (name is expected to be none) %s"), *GetName());
}

The member variables are already null/filled with default data by the time I know the level is about to be unstreamed

In the level blueprint graph, the event destroy node never seems to be called.


#My Question

What is the way I can know within the level script actor itself, that it is about to be unstreamed, before it is unstreamed, and its member vars are still filled with correct data?

#Request

if this is not yet possible please make it possible, to facilitate management of levels streaming in and out and enabling me to follow the object oriented model of keeping level-specific data within the level bluepirnt class

Thanks!

RAma

BeginDestroy is after garbage collection has been run and the object is about to be deleted giving it an opportunity to release any resources that may require time to complete.

Have you looked at ReceiveDestroyed? I can’t recall off the top of my head if it fires in the case of level streaming, but it probably should.

#Please Add ReceivedDestroyed to LevelScriptActor

I just tested it, and the log does not show up

It’s not that it shows up as “none”,

it does not show up at all

#.h

virtual void ReceiveDestroyed() OVERRIDE;

#.cpp

void AMyLevelScriptActor::ReceiveDestroyed()
{
	UE_LOG(MyLevelBPLog,Error,TEXT("STREAMING LEVEL RECEIVE DESTROYED (name should not be none) %s"), *GetName());
	
	Super::ReceiveDestroyed();
	//~~~~~~~~~~
}

BeginDestroy log does show up

//LevelScriptActor.h 		BeginDestroy()
void AMyLevelScriptActor::BeginDestroy()
{
	Super::BeginDestroy();
	//~~~~~~~~~~
	
	UE_LOG(MyLevelBPLog,Error,TEXT("STREAMING LEVEL UNLOADED (name is expected to be none) %s"), *GetName());
}

#Thanks Marc!

#:heart:

Rama

Alright, now that I actually took more than 30 seconds to look at the code I see the function you should be using: OnRemoveFromWorld

Yaay!

That did it!

#Thanks for the More than 30 secs Marc!

#:heart:

Rama

PS:

the code for others

void AMyLevelScriptActor::OnRemoveFromWorld()
{
	UE_LOG(MyLevelBPLog,Error,TEXT("STREAMING LEVEL UNSTREAMED (name should not be none) %s"), *GetName());
	
	Super::OnRemoveFromWorld();
	//~~~~~~~~~~
}