0

In my RPG, I have implemented dynamic system for item creation:

When I want to create a new item at runtime, I base its parameters(icon, name, ...) from a prefab that serves as item database and has such values for all items. I take those values and put them into an newly created class that serves as item in-game representation.

Then, when I want to save, I use JSON to save the data to harddrive. Now the problem comes:

JSON will save parameters like icon as InstanceID. From research I did, it seems InstanceId might change in between Unity runs.

So what is the propper way of saving resource references at runtime to disk and loading them in between Unity runs?

Zedd
  • 167
  • 3
  • 16
  • You should save the data that you are interested on, and later create it again reading it from the JSON. – Chopi Oct 11 '17 at 15:48
  • That is what I am doing. But as I said, JSON representation or an icon or other resources is its `InstanceId`. That might change in-between Unity runs AFAIK. – Zedd Oct 11 '17 at 16:06
  • You should make your own JSON for all the data, icon, position, status, etc So your json contains "icon" :"image.png" – Chopi Oct 11 '17 at 16:14
  • 2
    You can't serialize GameObjects, so you will need to serialize the information *about* those GameObjects, then when deserializing, create a new GameObject and apply that data to it. – Draco18s no longer trusts SE Oct 11 '17 at 16:43

0 Answers0