Repository: FlaxEngine/FlaxEngine
File: Source/Editor/Windows/Assets/JsonAssetWindow.cs (C#)

Code before:
using System;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Json;
using FlaxEngine.Utilities;

namespace FlaxEditor.Windows.Assets
{
    /// <summary>
    /// Editor window to view/modify <see cref="JsonAsset"/> asset.
    /// </summary>
    /// <seealso cref="JsonAsset" />
    /// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
    public sealed class JsonAssetWindow : AssetEditorWindowBase<JsonAsset>
    {
        private class ObjectPasteUndo : IUndoAction
        {
            /// <inheritdoc />
            public string ActionString => "Object Paste Undo";

            private JsonAssetWindow _window;
            private object _oldObject;
            private object _newObject;

            public ObjectPasteUndo(object oldObject, object newObject, JsonAssetWindow window)
            {
                _oldObject = oldObject;
                _newObject = newObject;
                _window = window;
            }

            /// <inheritdoc />
            public void Dispose()
            {
                _oldObject = null;
                _newObject = null;
                _window = null;
            }

            /// <inheritdoc />
            public void Do()
            {
                if (_newObject != null)
                {
                    _window._object = _newObject;
                    _window.MarkAsEdited();
                    _window._presenter.Select(_window._object);

Review comment (suggestion):
`_oldObject` and `_newObject` should be stored as `string` and use Json serialization to store in memory so it will properly work when code is hot-reloaded in Editor.

Code after:
using System;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Json;
using FlaxEngine.Utilities;

namespace FlaxEditor.Windows.Assets
{
    /// <summary>
    /// Editor window to view/modify <see cref="JsonAsset"/> asset.
    /// </summary>
    /// <seealso cref="JsonAsset" />
    /// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
    public sealed class JsonAssetWindow : AssetEditorWindowBase<JsonAsset>
    {
        private class ObjectPasteUndo : IUndoAction
        {
            /// <inheritdoc />
            public string ActionString => "Object Paste Undo";

            private JsonAssetWindow _window;
            private string _oldObject;
            private string _newObject;

            public ObjectPasteUndo(object oldObject, object newObject, JsonAssetWindow window)
            {
                _oldObject = JsonSerializer.Serialize(oldObject);
                _newObject = JsonSerializer.Serialize(newObject);
                _window = window;
            }

            /// <inheritdoc />
            public void Dispose()
            {
                _oldObject = null;
                _newObject = null;
                _window = null;
            }

            /// <inheritdoc />
            public void Do()
            {
                if (!string.IsNullOrEmpty(_newObject))
                {
                    _window._object = JsonSerializer.Deserialize(_newObject, TypeUtils.GetType(_window.Asset.DataTypeName).Type);
                    _window.MarkAsEdited();
                    _window._presenter.Select(_window._object);