Is there a way to get the byte size of a game object used in a scene during runtime? Similar to the php ‘filesize’ function?
$filename = 'somefile.fbx/jpg/prefab';
echo $filename . ': ' . filesize($filename) . ' bytes';
So far all I’ve seen regarding object size is how to return scale. I need actual bytes… partly for in build webGL profiling w/out having to be hooked up to the profiler; and partly for in-game metadata display.
Thanks in advance for any tips!
A file and a GameObject are very different beasts A file is pretty much just a continuous array of bytes. Easily Quantifiable. A GameObject is much more complex.
A GameObject consists of:
- A native C++ object
- A C# wrapper object for that native object
- Any number of components (Transform, Renderers, Colliders, custom scripts). Each of which has a native object and a C# wrapper as well
- Any number of child objects and granchildren etc… each of which with all of the above.
There simply isn’t a straightforward way to calculate the size of a particular GameObject at runtime.
1 Like
Thanks for the reply. That’s what I was afraid of. Hmm… perhaps I could try to grab the renderer.material.texture, along with the mesh assigned to an object, get a vertex count and assume ~12 bytes per vertex, then calculate a rough size off that. It would at least represent the bulk of the object size (scripts, transforms, colliders, etc. would be fairly negligible).
If you need to know how much memory is being used, start with the profiler.
Window → Analysis → Profiler
Remember, memory use in editor is completely irrelevant to how much memory is used on the actual target hardware. Each target hardware type will be completely different.