- Home /
Question by
Mahunreah · Feb 22, 2021 at 03:30 PM ·
serializationid
giving serialized objects their own ids
Hi
I have an NPC-Class like this:
[Serializable]
public class NPC: Human
[SerializeField] public string id;
public string ID { get { return id; } }
public void start()
{
string path = AssetDatabase.GetAssetPath(this);
id = AssetDatabase.AssetPathToGUID(path);
}
int age;
int money;
int dyingAge;
}
Ingame, I have a "townspeople register" that fills a List with up to X NPCs and giving each NPC a random name, age, money and dyingAge. This works, basically.
Now, I want to save this list in my saving system. My Items can be stored and restored by saving their IDs (no problem), but all of my NPCs have varying traits while sharing the same id.
I guess that happenes because I set each item by hand in the inspector, but let the peopleRegister populate on runtime, thus each path would relate to the NPC-script?
How could I change this? I guess there is an obvious solution, but I fail to see it.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613025618im_/https://answers.unity.com/themes/thub/images/avi.jpg)