- Home /
Assigning Assets to Static Variables
Right now, to access my assets using scripts, I have an object with a variable referencing each asset I want to use. They are assigned using the inspector. I could clean up my code a lot if instead of having this object lying around, I could just make them static variables in the class of the object. Is there a way to assign to these though? If the inspector can't do it, is there a way to reference them by name in the code or something?
Answer by whydoidoit · May 29, 2012 at 12:55 PM
You can load them if they are in a Resources folder using Resources.Load (I do this sometimes).
You could keep them as variables in an object, but have the object set a static Current when it does Awake(), then you can get it pretty easily from elsewhere (I do this too :) - this is also nice for overriding on a level by level basis
You can have them copy from a local variable to a static when an object does its Awake
Your answer
Follow this Question
Related Questions
[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer
Problem while editing animation clips on timeline 0 Answers
asset that cleans up the inspector? 1 Answer
Why doesn't my ScriptableObject save using a custom EditorWindow? 3 Answers
Custom Inspector when Selecting from Project Tree? 0 Answers