[Solved]Struggling to copy Component values

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

int tempHolder;
tempHolder = otherComp.value;
otherComp.value = 100000000000;

im not talking about specific variables within the component im talking about the whole thing
Plus id rather not create a variable for every field/property in my configurable joint lol

It’s called “deep copy”. What you want is not trivial.

2 Likes

Thanks, works perfectly