Hi
Im making a database framework for my games, so I created a bunch of lists as references then I tried to copy those lists but when I tried to modify the list copies the originals got modified as well, I then thought “Oh ok I need to create a new list then copy the list there” so I did, but I had the same result, I didnt understand what was happening but after much research I discovered there is two types of copies “shallow copy” and “deep copy” it seems even if you copy a list on a new list the new list still reference the original objects, so this is “shallow copy”, for a “deep copy” you need to copy the objects one by one, after much thought I come up with this Function:
void UpdateActors() {
foreach (Actor _Actor in MyDataBase.Actors) {
List<ArmorSlot> NewSlotList = new List<ArmorSlot>();
foreach (ArmorSlot _ArmorSlot in MyDataBase.ArmorSlots) {
NewSlotList.Add(new ArmorSlot() {Name = _ArmorSlot.Name });
}
List<BaseStat> NewStatList = new List<BaseStat>();
foreach (BaseStat _BaseStat in MyDataBase.BaseStats) {
NewStatList.Add(new BaseStat() {Name = _BaseStat.Name,BaseValue = _BaseStat.BaseValue });
}
_Actor.BaseStats = NewStatList;
_Actor.EquipedArmors = NewSlotList;
}
}
This doesnt copy the original object just creates new ones with some of the properties from the originals (just the ones I need) but this isnt instantaneous, also it resets the lists completely. It works al right I guess but I was wondering if there was a better way around this.