Search Unity

RegisterCompleteObjectUndo with mesh.vertices

Discussion in 'Scripting' started by hausmaus, Dec 9, 2017.

  1. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    If you want to undo changes made to a mesh's vertices using the built-in Undo class, how do you go about it?

    I tried:
    Code (CSharp):
    1. Mesh m = target.GetComponent<MeshFilter>().sharedMesh;
    2. Undo.RegisterCompleteObjectUndo( m, "Changed mesh" );
    3. m.vertices = someNewVerts;
    and although "Changed mesh" does appear next to Undo in the Edit menu, it doesn't seem to work. I also tried registering the parent GameObject, which also didn't work.

    I did do one test of modifying the GameObject's name, and that was undoable. But changes to mesh properties haven't been. I know they're all getters/setters and maybe that's why? In that case, is there a recommended way to do this, or should the wizard making these changes just offer its own history and restore functionality?

    (applies to 2017.2.0p4)