Cooking phase exceeded Maximum number of UObjects

Hi everyone, in a project I’m working on, at the end of the cooking phase for consoles (cooking ends without issue), I have this error:

Error: Assertion failed: Result + NumToAdd <= MaxElements [..\Engine\Source\Runtime\CoreUObject\Public\UObject/UObjectArray.h] [Line: 538] Maximum number of UObjects (26279936) exceeded, make sure you update MaxObjectsInGame/MaxObjectsInEditor/MaxObjectsInProgram in project settings.

Could you please suggest me what is the possible cause of this problem and where I could insert some logs to understand what is going wrong? Thanks in advance

The error message is already fairly descriptive here.

There is a limit on how many UObjects can exists in Game/Editor/Program that is set to a somewhat arbitrary value by default that we thought made sense. It’s possible your game contains/creates a lot of UObjects and that limit needs to be increased.

As long as you only see this message during cooking you can increase the Editor limit and your object count at runtime seems to still be within the limit.

You can set the limit in your DefaultEngine.ini like this to 3 million UObjects, the default should be 2M:

[/Script/Engine.GarbageCollectionSettings] gc.MaxObjectsInEditor=3145728

You can get a breakdown of the existing UObjects through the “obj count” console command in Editor or Game, but unfortunately not during cooking.

In Unreal 5.4 we’ve added the gc.DumpObjectCountsToLogWhenMaxObjectLimitExceeded console variable, which when set to 1 will print a uobject list to the log, allowing you to inspect the situation.

Unfortunately this is not present in 4.27, so if you might need to add some logic yourself.

You can take some inspiration from the change that added that option in 5.4 here on Github.

Kind Regards,

Sebastian