- Home /
How to avoid storing the same resource for each gameobject?
Let's say I have multiple copies of a GO with a spriterenderer component that has a script enabling it to swap sprites every once in a while. It seems nonsensical to me to store the sprite separately for each GO, since it is always the same sprite for each instance of the GO. So I should probably store the sprite as a static variable, but I don't know how to load anything into the static field. public statics don't show in the inspector, and if I run the loading of the sprite in awake it will run separately for each object which is the sort of stuff I am trying to avoid.
Should I then have a manager for these GO instances that stores the sprite and all instances communicate with this manager which gives them the needed sprite? What's the most efficient course in situations like this?
Answer by Bunny83 · Dec 31, 2019 at 12:51 PM
Use a scriptable object to store all your Sprite asset references and have each of your script simply reference the scriptable object asset. I highly recommend watching this video
Thanks! This seems to be exactly what I am looking for.
Your answer
Follow this Question
Related Questions
Static GameObject Variable 1 Answer
"The associated script can not be loaded." called on every object in the scene 1 Answer
What's a cheaper reference, GameObject or Transform? 2 Answers
convert Resources.LoadAll("RPGOBJ", GameObject) to gameobject array? 0 Answers
How to find in what Scripts or components an Object is connected 0 Answers