UUID - SerializeObject class - #if #endif wrapper - instantiated objects

What if I will want to expand this saving system for objects that were instantiated in the runtime?


This wrapper is gonna render those UUID functions useless, when i build the game. Any ideas how to change UUID generation? Or is it in the scope of future lectures?

Do you mean objects dropped by enemies in the RandomDropper class (that should happen automagically) or items created procedurally?

For procedurally generated items, some small changes need to be made to InventoryItem and all of the item stores (Inventory, Equipment, and ActionStore).

In InventoryItem, you need to create a virtual CaptureState and RestoreState. In the base class, these should just return null and do nothing.

In child classes of the InventoryItem, override CaptureState and RestoreState to save any procedurally generated information about the item.

Your procedurally generated items will need to have a pre-existing ScriptableObject in Resources to build upon. For example, a Sword of Amazing Power might have a randomly generated percentage boost to attack. When the item drops with ItemDropper, you’ll call a method to deal with this random generation (I once again have a do nothing virtual method in InventoryItem for this that is overridden by items that procedurally generate).

When saving a procedurally generated item, you use the same UUID as the original pre-existing object, but capture relevant information (in this case, the boost to attack).
When restoring, Instantiate a clone of the item retrieved by the UUID, and RestoreState it to put the information back.

Inventory, Equipment, and ActionStore will all have to do this same restoring.

As a rule of thumb, if an item is stackable, it’s not a good idea to use this procedural generation, because each instance of the same ScriptableObject(InventoryItem) is unique and by definition won’t stack with other instances of the same item anyways.

Thanks for the reply. I meant objects that are spawaned in the runtime, like objects dropped by enemies. I guess I need to proceed with course to this automagical RandomDropper class :). I don’t know anything about the Inventory, Equipment stuff you talked about, couse I’m not there yet in the course, but I will keep your reply noted.

Also I remembered that section of course: BONUS: Runtime Objects | GameDev.tv. I will need to implement some kind of Object Manager for my RTS game to get track of all the editor placed units and spawned units.

I will deal it after the course though. That will be couple months ahead ;).

In that case, the answer is “We get to that in the Integration section” :slight_smile:

Privacy & Terms