Deep Clone on a Serializable Class?
I am trying to clone the values for an item parsed from JSON. When I go to copy, value by value, and return a new instance of the class, which does not derive from any other class, I see all null values for the item I tried to clone. When I Debug.Log the values of the item from the database object, I get the correct values, but I cannot seem to figure out how to do a deep clone for a non-monobehaviour class.
My Attempt's Class
[System.Serializable]
public class ItemBase
{
public string ID;
public string Icon;
public string Name;
public bool Consumable;
public int Cooldown;
public int Duration;
public string EffectDescription;
public string Description;
public string SFX;
public StatBonus Bonuses;
public void Clone(ItemBase newItem)
{
this.Bonuses = new StatBonus();
this.Consumable = newItem.Consumable;
this.Cooldown = newItem.Cooldown;
this.Description = newItem.Description;
this.Duration = newItem.Duration;
this.EffectDescription = newItem.EffectDescription;
this.Icon = newItem.Icon;
this.ID = newItem.ID;
this.Name = newItem.Name;
this.SFX = newItem.SFX;
this.Bonuses.Attack = newItem.Bonuses.Attack;
this.Bonuses.HP = newItem.Bonuses.HP;
this.Bonuses.Tolerance = newItem.Bonuses.Tolerance;
this.Bonuses.Stamina = newItem.Bonuses.Stamina;
}
}
Could the fact that it is not derived from Monobehaviour that is causing issues?
Your answer
Follow this Question
Related Questions
Instantiate keep on cloning my object - How can I stop it!? 0 Answers
How to save and load all gamebjects which are cloned at runtime???? 0 Answers
Prefab always instanciated at 0 1 Answer
Having problems with custom objects in my array - BCE0019 0 Answers
Unsure of how to convert c# public class to javascript 1 Answer