Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Deep Clone on a Serializable Class?

$
0
0
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?

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>