- Home /
Giving a ScriptableObject asset reference to all instances of a MonoBehavior?
Say I have a ScriptableObject which holds a simple dictionary-like data structure. (For each type of in-game "resource" - think wood, steel, fuel, etc. - it defines a corresponding Sprite. But that doesn't matter.)
So I make an instance of that ScriptableObject, as an asset. I configure the asset in the Inspector, assigning each "game resource" its corresponding Sprite.
Now, I have a MonoBehavior which will be attached to "game resources". How can I make sure that every instance of this MonoBehavior (including those instantiated at runtime) has a reference to the ScriptableObject asset from before?
I see that the MonoBehavior script itself, in the Inspector, has a slot for attaching a ScriptableObject reference. However, it says "default references will only be applied in edit mode." This makes me a bit nervous about using this feature; is it the correct approach?
Any help would be appreciated! I'm sure there's a simple way to do this...
I see that using Resources.Load() would also be an option, but the documentation recommends against this.
Also, I forgot to mention: I know that I could drag the Asset into the Inspector view of each $$anonymous$$onoBehavior. But this won't work for when I Instantiate the $$anonymous$$onoBehavior mid-game.
Your answer
Follow this Question
Related Questions
ScriptableObject reference resetted after a method is finished. 2 Answers
Show on ScriptableObject all other ScriptableObjects that reference it 0 Answers
Unique function for each instance of a scriptable object 2 Answers
Unity : Singleton ScriptableObjects resets after play 1 Answer
Using LookAt with Scriptable Objects 0 Answers