Overriding the Component Copy functionality in Inspector

Does Unity allow me to override the Copy/Paste functionality of a Component in the Inspector window?
9395633--1314854--upload_2023-10-7_16-14-51.png

For example, suppose I have a specific component that contains references to other components and I want the copy and paste to work different for just this one component, by copy-pasting new versions of its children components into the new gameObject (or anything else, functionality is unimportant).

I know I can create a custom editor with buttons to do it but preferably I’d like if it would be done using the existing Copy-Paste provided.

All that stuff, I believe, is locked up in the internal part of the engine’s code. Pretty much any copy-paste stuff, last I checked, was all internal and inaccessible.

You can of course make a custom MenuItem that only shows up for specific components.

Thanks for the response @spiney199 !!
I will proceed with a custom editor but I do hope Unity takes a page from Microsoft efforts with ASP.NET and allow us hook into and override these type of core functionality in the future.

There’s but one thing you can check upon paste: does it run the Reset() or OnValidate() event methods?

If so, you could perhaps use those to do what you want, even if it means applying it in every call of these methods (as long as it isn’t expensive).

You can integrate your own copy paste functionality inside a CustomEditor

private static void DrawContextMenu(Rect stateRect, SomeDataModel someDataModel, GenericMenu menu)
    {
        if (Event.current.type == EventType.ContextClick)
        {
            Vector2 mousePos = Event.current.mousePosition;
            if (stateRect.Contains(mousePos))
            {
                string systemCopyBuffer = EditorGUIUtility.systemCopyBuffer;
                if (!string.IsNullOrEmpty(systemCopyBuffer))
                {
                    SomeDataModel copiedData = null;
                    try
                    {
                        copiedData = JsonUtility.FromJson<SomeDataModel>(systemCopyBuffer);
                    }
                    catch (Exception e)
                    {
                    }

                    if (menu == null)
                    {
                        menu = new GenericMenu();
                    }
                    menu.AddItem(new GUIContent("Copy Stuff"), false,
                        userData =>
                        {
                            EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(userData);
                        }, someDataModel);
                    if (copiedData != null)
                    {
                        menu.AddItem(new GUIContent("Paste Stuff"), false, userData =>
                        {
                            SomeDataModel model = (SomeDataModel) userData;
                            model.Stuff= copiedData.Stuff;
                         
                        }, someDataModel);
                    }
                    Event.current.Use();
                }
            }
        }
    }