Storing data - Prefab vs ScriptableObject + Asset

Hi.

I have a class animal which inherits from MonoBehaviour.
I need this class to set data for several animals e.g. cat, dog etc with the editor during design time.

Right now I create a GameObject for each animal, add the animal script, set the data for the animal via the editor and save it as a prefab. The prefab is linked by several other GameObjects in the scene just to access the data.

This is working fine so far. But I’m asking myself if it would be a better approach to inherit from ScriptableObject and save this as an asset. Then I’d link these asset instead of a prefab to the other GameObjects which need to access the data.

What is be the better approach of this two? Any pros and cons?

There are no real pros and cons. ScriptableObject is a bit “complicated” to use in contrast to a prefab with a monobehaviour.

The differences are:

  • ScriptableObject has less overhead since it is just a single class instance. A prefab is always composed of: A GameObject, a Transform component and your script component.
  • ScriptableObjects have to be created manually as asset. In the past you would have to write editor code to actually instantiate one and save it as asset. Now there is the CreateAssetMenu Attribute which automatically can add a menu item to the “create asset” menu where you can directly create a new asset of your ScriptableObject.

The “CreateAssetMenu” attribute has really improved the usage of ScriptableObjects. So, yes, if you have a lot of animal “types” you want to define using a ScriptableObject might be better. It’s always depends on the usecase. The prefab approach has the additional advantage that you could add more components to certain instances and have all grouped together in one asset. With ScriptableObjects you only have that one instance of your class.