for( FObjectIterator It ; It ; ++It ) {…
Hi,
I wonder how can I get the number of all currently existing UObjects in the engine. I mean all objects: not only actors, but everything that is an UObject. This is necessary for the debug tool I am currently writing.
Robert.
Hi, thanks for the answer. Your method would definitely work. But in my case the idea is to get the number without iterating through all the objects. I have created a data structure that holds entries with information about each UObject in a TArray. In order to reduce number of memory reallocations I want to presize the array by calling Array.Reserve(X) where X is the total number of UObjects.
I believe there’s no way without modifying the source. Technically, there’s:
GetUObjectArray().Num()
but I think it’s behind an API not available to end users (COREUOBJECT_API)
Great! Looks like this is exactly what I need. I can modify the source to expose this number. Thank you!
In 2021 the name is :
extern COREUOBJECT_API FUObjectArray GUObjectArray;
declared in Engine\Source\Runtime\CoreUObject\Public\UObject\UObjectArray.h
You can see the number of objects with:
int allObjects = GUObjectArray.GetObjectArrayNum();
To be honest, I suspect that the length of GUObjectArray is not number of UObjects. It may be more like a pre-allocated pool ? Can someone answer me ?