Why is the actors counter in scene outliner showing a negative value?

The game I work on spawn a lot of actors at runtime. As the amount of actors and memory usage started to get high (over 2GB), I coded a clean up function that discard useless actors.
Everything work, and this allow me to keep the memory usage at a fixed amount.

Except that the actors’ counter in the scene outliner reach a negative number.
No crash, no error in the output. Just this negative number.

9419-negative+-+unreal+editor.png

I’m fairly new to Unreal, and I don’t know what cause the counter to behave like that. I don’t even know where the counter fetch the negative value.

I found the counter : SSceneOutliner::TotalActorCount.
Trying to debug…

I believe this is a bug in the UI.

If you look at how TotalActorCount is modified, you’ll see it is incremented or decremented each time an item is added or remove. When I destroy a bunch of actors at once, the counter get out of sync by trying to refresh and then remove item.

What I don’t understand is that ActorToTreeItemMap hold an accurate counter of actors in the TreeView. Replacing the value of TotalActorCount by ActorToTreeItemMap.Num() solve my problem. What is the purpose of TotalActorCount?

Hi ,

Are you able to make this happen in a brand new project using only your spawning and cleanup code?

I manage to reproduce the issue with a few modification to the “Code First Person” template.

The spawning and cleanup :

//ATempActor is an AActor with a RootComponent
//Actors is std::vector<AActor*>
ATempActor* tempActor = World->SpawnActor<ATempActor>(ATempActor::StaticClass());
if (!Actors.empty())
{
	tempActor->AttachRootComponentToActor(Actors.back());
}
Actors.push_back(tempActor);

if (Actors.size()>10)
{
	// each time, Scene outliner lose 19 actors, instead of 10
	for (auto * actor : Actors)
	{
		actor->Destroy();
	}
	Actors.clear();
}

I can send all the code if needed.

I tried doing some testing on this, but was unable to see the actor counter display negative values. Could you please send the code you used in the first person template to reproduce this issue?

Generate a project named ActorCounter using the “Code First Person” template. Replace the content of the “Source” folder with the attached zip.
source.zip

I don’t know if there is a better way to send you the code.

There is a new class ATempActor, and some changes inside AActorCounterCharacter::OnFire().

Start the game, you should have 41 actors. Click 11 times to run the OnFire() method. Counter will drop to 32. Continue until you reach negative.

Hi ,

Thank you for providing the information and code for this issue. I was able to reproduce it and have submitted a report about the issue to the development team for further investigation.

Thanks,

I am getting this behavior as well. If any additional information is needed, I can try to help as well.

Hi afuzzyllama,

We have a report in place for this issue (TTP# 340804) and our development team is aware of it. Unfortunately I cannot make any estimates with regards to when this will be resolved.

I just provided a fix: https://github.com/EpicGames/UnrealEngine/pull/490
I hope it can help to resolve this issue soon.

We’ve merged in Mathias’s change in sha$8dd90c19bc9b19fd6c0dd36bd82483ec7d21df4c if anyone wanted to get the fix earlier than 4.6.

Thanks for the contribution!