Unity-Technologies / guid-based-reference

A component for giving Game Objects a GUID and a class to create references to objects in any Scene by GUID
Other
625 stars 71 forks source link

GameObjects created at Runtime #27

Open steve18624 opened 10 months ago

steve18624 commented 10 months ago

This is a great solution. Thank you.

I recommend that you add a disclaimer somewhere that this system requires customization for save systems that must accommodate saving data about GameObjects created at runtime. As is, this solution is primarily for GameObjects created in the Editor. Stating that this solution can be used for save games without that warning may lead someone to implement this incorrectly.

To clarify, you can create a GameObject and add the GuidComponent at runtime. GuidComponent will create a unique GUID; however, it will not serialize it for future play sessions. You must create a custom save system that saves the GUID and other relevant data about the GameObject (e.g. position). Then on the next play session (runtime session), you must instantiate that object and load in the GUID into the GuidComponent and the other data into the GameObject (or custom class). However, when you add the GuidComponent to the GameObject it will assign a new GUID. You cannot load your previous GUID in GuidComponent.