- Home /
Singleton Inventory
Yesterday I asked a question regarding serialized class of a inventory system.
Today is a related question(s), but as is a different one, I thought that would be nicer to post it as another thread.
A-Is it smart to design a inventory system as a singleton? B-How the saving would be? C-The singleton should be or not a MonoBehavior?
I'll stop here.
Thanks!
Answer by WilliamLeu · Mar 01, 2013 at 05:26 PM
A) I didn't see your original question, but I think it depends on your game and its design, no reason that wouldn't work though. Just make sure that the inventory class only belongs to one character. If you have an inventory class that manages the inventory of all/multiple characters, might as well store the inventory information in the individual respective characters.
B) The differences in performance and resources are so small that I wouldn't worry about it. Worry about what's more elegant conceptually, and what's the most sane to implement.
C) If you were going to have a singleton, I would recommend making it a MonoBehaviour. I would have a "GameManager" GameObject in the scene where all the singletons and global states go. Then in the Awake() function of the singletons, have it set the static instance to itself. That keeps things modular (in the spirit of MonoBehaviours), and you can expose variables through the inspector during edit and runtime. You do loose the ability to change the code during runtime without restarting the game though with static variables to MonoBehaviours.
i'm really not sure about how to pull this out.
Of course I'm implementing some other features of the project, but this is a key one and my "time is running out". (remember Command and Conquer: Red alert sound track?)
Your answer
![](https://koobas.hobune.stream/wayback/20220613093635im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Need experienced opinion: Saving a players inventory: XML or PlayerPrefs? 1 Answer
SerializationException: serializationStream supports seeking, but its length is 0 1 Answer
Button OnClick() function stops working after instantiating the prefab. 1 Answer