How to get the number of UObjects in scene?

How do I get the number of UObjects in the scene using TObjectIterator?

I tried the following , but I get an unresolved external error for Count++.

float Count = 0;

    for(TObjectIterator<UObject> UObjectIt; UObjectIt; ++UObjectIt)
    {
        if(UObjectIt->GetWorld() == currentGameWorld)
        {
            UObject* ObjectModel = *UObjectIt;
            Count++;
        }
    }

I ran this code, and I didn’t get any errors.

1 Like

thats kinda weird. I ran it several times, and it returned unresolved symbols. but it works now! seems like I had some other problem else where.

Question, to use this functionality, do I need to call the function created (that calculate the used UObject in scene) any where in my project (i.e. call the function from any class that uses UObject), or no need to do that?

The reason im asking is that I don’t see any warnings in logs/screen (even if I switch off the order of < or > 90 percent.

Yes, you do need to call this. It doesn’t have to be from a class that uses UObject as long as to pass in a world object reference and make it static. There’s a meta specifier to make it clean.

Since it iterates through every single UObject, it might be best to do it only occasionally. The difference between 90% and 100% is absolutely massive, so it’s likely you could just do it whenever loading a save.

1 Like

Great, Thank you.

1 Like