0
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.