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?
GameObject go = GameObject.Find(values); Undo.RecordObject(go,"setting at rest"); // Do transforms float x = float.Parse(p_values); float y = float.Parse(p_values); float z = float.Parse(p_values); 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