I have a prefab that essentially is just a lookup table for other prefabs:
OrbPrefabTable
-List Ids
-List Prefabs
I have another script on an object in my scene that has a direct reference to the OrbPrefabTable script on a prefab in my project. I simply access the values on the prefab asset directly from my code without first instantiating the prefab. I do not alter the values on the prefab or use it any other way. It is treated as entirely immutable. Is there a problem with this? The Editor is crashing on occasion and sometimes the prefab gets another Transform added to it when I exit play mode.
The same goes for ScriptableObjects - do I actually have to create an instance of them before I use them?
I have a feeling this is a case where the Unity Serialization system is broken.
I can see why I “shouldn’t” but unity lets you without problem, and I have been doing it this way for years. I only started questioning the technique recently due to errors I have been getting in combination with community chatter concerning serialization problems.
Switching to ScripatableObjects is worth a try. They have so much overhead in so far as editor scripting and making inspectors though, which is a bummer.
They overhead is minimal. You can make them more complex if you want, but typically I don’t bother creating custom inspectors for them. Once created, the public vars are all available in the inspector like any other.
I am surprised that accessing values on a prefab in the project would work. I wouldn’t have expected it to, that is kind of what ScriptableObjects are designed for.
You don’t instantiate these, but you should load them before using them.
What overhead are you referring to? There’s only the minor issue that you need to create the ScriptableObject asset and save it into your project. This helper script (ScriptableObject Factory) can solve that issue for you.
You don’t have to create a custom inspector for it, Unity will use the default one so you can edit it with no issues.