Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Supporting Undo in a TMP_InputField?

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

  1. larryPlayablStudios


    May 15, 2018
    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.