I’m facing a problem where i can’t seem to keep the orginal values of components.
myComp = otherComp;
otherComp.value = 5;
Debug.Log(myComp.value); //5
I understand this behaviour is because c# classes are defined as pointers so changing the value of a component pointing to another component will also alter the value of the assigned component … if that makes sense.
what im trying to do is to copy the values of these components eg
// within class
public MyComponent myComp;
public MyComponent originalValues;
void Start()
{
// ideally id do something like this
// im assuming i would use reflection in the 'CopyValuesFrom' function but im not sure how :?
// this function here ↧ is basically what i need to script
originalValues.CopyValuesFrom(myComp);
}
void Something()
{
// if i change the values of 'myComp' here, 'originalValues' would not change
}
Thanks for any help