- Home /
Are MonoBehaviours heavier than ScriptableObjects? what's the difference in memory footprint between them?
When it comes to data storage, first thing that comes to mind is regular C# classes - most the times these work. But if we want this data to be inspected and fully support inspector stuff (multiedit, undo/redo support) then regular classes won't cut it - (For undo for example, Undo.RecordObject takes a UE.Object, and getting SerializedProperties to cope well with your System.Objects is pure pain in the butt....) - so we turn our attention to the other 2 usable classes: MonoBehaviour
and ScriptableObject
.
Some people use SOs, some use MBs. I tend to use MBs all the time cause SOs don't live in prefabs, and to go around that I'd have to manually create an asset and save it, then update it when I change it, and if I want to add to it I have to AddObjectToAsset (or something)... etc etc. As opposed to just creating an object, attaching it the MB, and just dragging-dropping it to the project folder making it a prefab, and... done.
My question is: Are MBs heavier (in terms of memory) than SOs? Well logically it should be heavier cause SO directly inherits UE.Object, and MB inherits Behaviour, which in turn inherits Component, which inherits UE.Object - so there should be a difference in memory footprint. But how much? how big is that difference? is it one of those differences where you could just ignore it relying on the fact that modern machines these days could handle a lot?
Note: I care mostly about PC builds, not mobile.
Thanks!
I don't think there is any harm in using behaviors to do data storage. I did it effectively before fully understanding scriptable objects. But in the end you are going to run into the same problems of data shearing with inherited classes and references not being serialized. I guess it would be possible to have objects for each one just like how you would create ones for scriptable objects but now you are just adding even more overhead. If it is simple go for it. If not I would invest in a few editor scripts to handle the scriptable objects.
I guess it would be possible to have objects for each one just like how you would create ones for scriptable objects
What you meant with 'for each one'?
Just like with scriptable objects if you want to do a list of the class 'Animals' you would need to make the class Animal inherit from scriptable object and then 'Dog' and 'Cat' from that. You could do that but by having Animal inheriting from $$anonymous$$onobehaviour ins$$anonymous$$d. Then you make an empty game object or prefab for each and construct your data structure by copy pasting and dragging or using an editor script. Not recommended at all, but do able.
Your answer
Follow this Question
Related Questions
[Custom Editor] MonoBehaviour vs Scriptable Object 0 Answers
ScriptableObject and Monobehaviour 1 Answer
MonoBehavior, ScriptableObject and Object memory usage & performance 0 Answers
Memory usage of Sprites in a referenced Scriptable Object 0 Answers
Are there any reasons why I should use ScriptableObject instead of MonoBehaviour (or vice-versa)? 3 Answers