# Unity: Saving scene after using script to change object positions

I have a c# script which makes some edits to object positions in the editor. It does this by reading some values from a csv file and then changing the value of transform.position for each gameobject. When I run the script all the objects appear where I want them to be in the editor. However, the editor doesn't seem to recognise any change and when I save and reload the scene the objects have reverted to their previous positions. Any ideas?

Code:

GameObject go = GameObject.Find(values[1]);
Undo.RecordObject(go,"setting at rest");
// Do transforms
float x = float.Parse(p_values[0]);
float y = float.Parse(p_values[1]);
float z = float.Parse(p_values[2]);
Vector3 p = new Vector3(x,y,z);

go.transform.position = p;


Aha I think I see my error, Undo.RecordObject want the specific object that is changing rather than the gameobject. I've edited the code to Undo.RecordObject(go.transform,"setting at rest"); and it now seems to work

## 1 Answer

I see my error, Undo.RecordObject wants the specific object that is changing rather than the gameobject that is being modified (this wasn't that clear to me from the docs). I've edited the code to Undo.RecordObject(go.transform,"setting at rest"); and it now seems to work

• if it solves the problem, please accept your answer by clicking the tick icon. – Mohammad Zamanian May 31 '19 at 10:48
• Thanks for the reminder, I had to wait some time before approving the answer – A. Bollans May 31 '19 at 15:21