Setting x on Vector3 via reflections is not working.

I thought the two lines of code at the bottom of this block of code should be equivalent.

axisMethods[AxisType.Proceed] = "x";
vectorField[axisMethods[AxisType.Proceed]].SetValue(texturePoint, proceed);            
texturePoint.x = proceed;

vectorField is a dictionary of FieldInfo.

texturePoint.x = proceed works as expected. But when I comment that out so I can start using SetValue instead the code does not work.

Using Unity 2020.1.10f1, if that matters.

Well this doesn’t work because SetValue takes in an object reference. The whole reflection system works on the base class “object”. So when you pass in your “texturePoint” variable, that value will be boxed into an object. So the vector3 value is copied into a “box” / a heap object to hold the value and that one is processed by the SetValue method. Since you create the box “on the fly” you loose the reference to the boxed value right after you called SetValue on it. In any case your original variable of course won’t be affected. You have to do:

// explicitly box your Vector3 value
object tmp = texturePoint;

// do your reflection stuff on the boxed value:
vectorField[axisMethods[AxisType.Proceed]].SetValue(tmp, proceed);

// explicitly unbox the value and copy it back to your original variable:
texturePoint = (Vector3)tmp;

There’s no way around this. Value types and reflection do not play well together. You will always allocate memory when using reflection on value types.