ScriptableObject allocates memory if the link is empty?

Tell me how to do it in terms of memory optimization.

I have a vehicle script. Only one vehicle has a weapon. I want to make a script of weapons. How best to keep a link to it? What would the vehicles without weapons have, was not the allocation of extra memory?

As an option to make a script of weapons “ScriptableObject”. And I add the variable “public VehicleWeapon weapon” to the script of the vehicle itself. If the field is empty, will the memory be allocated?

It sounds like you just need a private variable and a prefab variant.

There’s no memory cost difference between that field having a value or not. In either case it’s just a pointer- either a pointer to the SO, or a pointer to null.

A pointer’s 8 bytes, so if you have 1000 of these vehicles, the additional memory cost of the public field is 8 kilobytes. Ie. you’ll live.

1 Like

Thx!