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.


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.