This is not something that we can fix. It's how the Undo+Serialization system works in Unity. The system took a snapshot of the UIDocument before entering Play mode. When the script changes the text content (inside UI Toolkit), the system does not know about this change. UI Toolkit elements are not part of the GameObject/MonoBehaviour data. When the user changes the position the GameObject, this action IS recorded. So when you Undo, it simply resets the UIDocument and reloads the UI from UXML, undoing any changes the script made during runtime.