I created a variable character, holding the class characters, and then I made it equal to an element in an array of characters called playerdatabase, and then I want to modify characters in runtime without affecting playerdatabase. however, whenever I change values in character, it affect the value I copied from back in playerdatabase. I’m guessing that character was made an reference to the element of playerdatabase instead of having separate values, how do I make character a copy instead of a reference of the element in playerdatabase?
public characters character;
character = mechanics.playerdatabase[controlscript.activeParty[partyIndex]];
I figured, I tried a method I found on google, this:
public static T DeepClone<T>(T obj)
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;
return (T) formatter.Deserialize(ms);
}
}
but I couldn’t find MemoryStream or BinaryFormatter. can anyone post a method I could use to create a hard copy of a object?
edit : nvm, found memorystream and binaryformatter but still doesn’t work because everything has to be marked as serilizable.
edit2: solved it, I only hard copied the part that needs to be hard copied and everything else was shallow copied.