- Home /
What is the best way to load an instance of a gameObject when loading a saved game?
I am making an inventory system that contains a List<> of a Items and methods to modify and search said list. The Item data type holds information about a game item such as its name, a description, how many of that item are in a stack, etc. For saving/loading purposes, I'm having the Inventory write data about the Items in the Inventory to a file and then load that information to recreate the Inventory.
The item also holds a reference to a gameObject that is the prefab of the gameObject it was attached to prior to being collected so it can be dropped in the game world. For the inventory file, I have been writing the path of the item prefab in the Resources folder so that when I load the inventory I can use the Resource.Load function to set the gameObject instance.
While this method works I'm curious if there is a better way to accomplish this that uses less memory than using the Resources folder method.