Editor World starts ticking in PIE if you press F8

For a while on our project we have had some big slowdowns when going out of the player with F8.
The slowdown would get worse and worse until the editor becomes unusable. There would also be some huge memory spikes when stopping play. (up to 10 GB)

We just tracked it down to what seems to be a problem with AActor::ShouldTickIfViewportsOnly()
We use this to draw quite a bit of debug graphics in editor mode when the game is not running.

It seems like when you unposses the actor with F8, this function starts getting called again and the Actors in the Editor World (Not the PIE world) start ticking again. (This seems like a bug?) But also all the debug graphics that would be drawn (We cant see it because we are in PIE) appears not to be cleaned up correctly, because the number of batched lines just keeps increasing. (We saw up to tens of millions of lines in the LineBatchComponent.

The workaround for us has been to use this line instead of just returning true:

bool ASomeActor::ShouldTickIfViewportsOnly() const { return GEngine->FindFirstLocalPlayerFromControllerId(0) == nullptr; }

This prevents ticking when the game is playing.

Hey Amimoller,

I’m having issues reproducing this. Could you post a list of what debug commands are you using?

I managed to reproduce this in the first person template. Here is how:

In Character.h add this:

virtual bool ShouldTickIfViewportsOnly() const override;
virtual void Tick(float DeltaSeconds) override;

UPROPERTY()
bool InGame;

in Character.cpp add this:

void ACharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	InGame = true;
        .......

bool ACharacter::ShouldTickIfViewportsOnly() const
{
	return !InGame;
}

void ACharacter::Tick(float DeltaSeconds)
{
	if(!InGame)
	{
		DrawDebugSphere(GetWorld(), FVector::ZeroVector, 2000, 300, FColor::Red);
		UE_LOG(LogTemp, Warning, TEXT("This should not log ingame"));
	}
}

In the editor you will see the log print and the sphere in the world.
Start the game, the log print will stop.
Press F8 to go into fly mode. Log will start printing and your framerate will take a massive hit.

//Cheers
Jonas

Could you test disabling the draw debug graphics and see if the performance still takes the hit? I just want to be sure we aren’t seeing another underlining issue.

As far as performance while drawing debug graphics, the debug info is being drawn each frame. So a large hit like you are seeing is expected, especially over time. Are you planing to use the debug graphics in the final game?

Yes everything is fine if i dont draw any debug graphics.
And in the repro im only drawing one sphere per frame, which runs fine until you press f8 and then you go down to 5-10 fps.
We dont use the debug graphics in game, we use it in the editor, hence why we make ShouldTickIfViewportsOnly() return true.

If i can just send you the repro project maybe that is easier?

//Jonas

Sure. If you can make a test project that is under 5 mb you can upload it directly to here. Otherwise, you can upload it to Google Drive, Dropbox, etc and then PM me a link to download it directly over the Forums.

Hi Amimoller,

We haven’t heard back from you in a few days, so we are marking this post as resolved for tracking purposes. If you’re still experiencing this issue, please feel free to post back here with additional information to reopen the post.

Cheers,

TJ