Search Unity

Question Supporting Undo in a TMP_InputField?

Discussion in 'UGUI & TextMesh Pro' started by larryPlayablStudios, Feb 16, 2023.

  1. larryPlayablStudios

    larryPlayablStudios

    Joined:
    May 15, 2018
    Posts:
    31
    I've been working on a runtime text editor using a TMP_InputField, and I would really like undo support for it.

    This is for a development tool that needs to run in Unity Editor, so an implementation using the editor's undo system would be fine.

    I've tried using both of these in the onValueChanged callback, but neither works reliably as I'd expect for a text editor.

    Undo.RegisterCompleteObjectUndo(inputField, "Text editing");
    Undo.RecordObject(inputField, "Edited Text");

    Undo seems to work correctly out of the box when typing directly in the inspector window, it just doesn't work for me using the runtime input field entry within the game view.

    Can anyone point me in the direction of properly implementing this, or is there a better route than using the unity editor? I could save my own undo history, but it'd be annoying if cmd/ctrl-z triggers both the editor undo and my runtime undo.

    Thanks!