- Home /
Undo not properly working for some Rigidbody properties
I am writing a Custom Inspector for Rigidbody. It works well for properties like mass
, but not for others like centerOfMass
and such. Here is the relevant code of my OnInspectorGUI()
:
EditorGUI.BeginChangeCheck(); centerOfMass = EditorGUILayout.Vector3Field("Center of Mass (m)", rigidbody.centerOfMass); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(rigidbody, "Rigidbody CoM Change"); rigidbody.centerOfMass = centerOfMass; Debug.Log("center of mass change registered"); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene()); } if (GUILayout.Button("Recalculate Center of Mass")) { Undo.RegisterCompleteObjectUndo(rigidbody, "Rigidbody CoM Reset"); Debug.Log("center of mass reset"); rigidbody.ResetCenterOfMass(); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene()); }Results:
CoM changes are registered in Undo stack
Scene is marked dirty and can be saved
"Edit/Undo Rigidbody CoM Reset" and "Edit/Undo Rigidbody CoM Change" do not undo COM modifications.
I am using RegisterCompleteObjectUndo
since with RecordObject
the changes are not even detected and put on the undo stack.
Any hints to get my custom rigidbody inspector working nicely are highly appreciated!
So far I shied away of writing my own serializable rigidbody data class. I presume this will entail quite some lines of extra code, maybe also a CustomPropertyDrawer and an additional Component per Rigidbody in my GameObjects . Any suggestions how to do this nicely are also very much appreciated.
Thank you for your time and for your help.
Your answer
Follow this Question
Related Questions
How to change Rigidbody interpolate through script. 1 Answer
Rigidbody mass not updating in inspector after calling SetDensity 2 Answers
how to change Rigidbody "interpolate to none" through script. 1 Answer
Multiple Cars not working 1 Answer
Make a custom inspector that shows a group of variables in form of list 2 Answers