Hello there, i have performance design question, about unused structure arrays instead of variables.
For example i have item structure, for inventory logic, it should contain multiple structs inside, to have specific data about various item types, weapon/armor or consumable.
But if my item is currently a consumable, it will have unused weapon and armor data there aswell, which will probably consume extra memory, like in first image below, item has various structs with various type data.
If i will use array variable with single element for current type data, like in the second image, will it be better? So array with 0 elements seems does not show any variables until it has elements, but i am not sure.


Is it good workaround to use only specific type of data inside same struct? Or the engine will ignore this workaround and considers empty array as the default variable even if there is no elements, and will load it into memory by making this approach useless?
Please answer anyone who understands how the engine structure logic works.
Unless you’re going to have 10s of thousands of different kinds of things you can have in your game / inventory, it doesn’t matter. It’s only a few K, and pales massively into insignificance in comparison to things like texture memory.
If you’re really worried about it you could use C++, then you can use variant records, where you can have different data types occupying the same space.
Thanks for answer, well i understand it, but i want to be sure how it works in the engine, so to know that empty arrays are really empty on memory, or they are not.
It can really go large if each of those structs will have many dynamic vars, so this is why i am interested.
I don’t want to go into C++, there are many possible ways to workaround this, but i want to test this one, as it seems the easiest way to close data inside struct, so i need more exact answer.
Arrays only take up the space you use.
So its really being better at design to keep memory? If so then it is probably best approach for large inventory or save storage, by using single element array of desired data, and keep other unused data in empty arrays. Thanks for clarification!