January 2021

Counting memory in UE4

UE4 has many stats and memory counting mechanisms with great tools to display it. Unfortunately useful tools, like Statistics window or Size Map, display not really useful data. Major problem is that in-editor memory is reported and not memory for a cooked game. Another problem is that even this memory is not always properly counted. Under the hood UE4 has two memory size counting mechanisms. One is serialization based and uses FArchiveCountMem serializer. Another is based on calling a special GetResourceSizeEx virtual function defined in UObject. You can see both used in functions like UEngine::HandleListStaticMeshesCommand. Digging deeper you can see that in fact GetResourceSizeEx internally uses FArchiveCountMem to count memory of a current object.

During my work on UE4 based games (Evil West and Shadow Warrior 3) counting memory properly was a top priority. Therefore I modified memory counting mechanisms to count memory for specific cooked platforms. Using this corrected counting mechanism I was able to create easy to use level streaming budgets (displayed in the viewport) and assets’ budgets based on Data Validation interface (https://docs.unrealengine.com/en-US/ProgrammingAndScripting/ProgrammingWithCPP/Assets/DataValidation/index.html).