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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Improved clipboard copy/paste

Discussion in '2020.1 Beta' started by Aras, Feb 24, 2020.

Thread Status:
Not open for further replies.
  1. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Since 2020.1 alpha 23 there is this release notes item: "Editor: Added Copy/Paste support for most inspector fields (vectors, colors, object references, gradients, animation curves ...). All they produce text in system clipboard, and the copied values can be sent to someone else or pasted into another Unity instance." Here's a bit more about it.

    Added Copy/Paste keyboard shortcuts and context menus to Serialized Property fields (e.g. in Inspector, or anywhere else they are displayed) for most types. This is: Vector2, Vector3, Vector4, Quaternion, Color, Object Reference, Gradient, Animation Curve, Rect, Bounds, LayerMask, Enum, Bool, RectInt, Vector2Int, Vector3Int.


    All these produce text-based representation in the system Clipboard, so you can send that to someone else on a chat, or paste into a text document, or into another Unity instance, etc. Examples of text representations produced by copying simple fields:

    Vector3(10,11,12)
    Vector3(60.0,30.0,45.0)
    Quaternion(0.531975687,0.0222599953,0.200562119,0.822363079)
    #ACFF04
    Color(0.1,3,4,1)
    Bounds(1,-2.5,3.7,1.5,-2,7.7)



    More complex ones are copied/pasted from a TypePrefix:JSON format, for example an animation curve:
    UnityEditor.AnimationCurveWrapperJSON:{"curve":{"serializedVersion":"2","m_Curve":[{"serializedVersion":"3","time":0.016666412353515626,"value":0.660369873046875,"inSlope":2.0,"outSlope":2.0,"tangentMode":0,"weightedMode":0,"inWeight":0.3333333432674408,"outWeight":0.3333333432674408},{"serializedVersion":"3","time":1.0,"value":1.0,"inSlope":0.0,"outSlope":0.0,"tangentMode":0,"weightedMode":0,"inWeight":0.3333333432674408,"outWeight":0.3333333432674408}],"m_PreInfinity":2,"m_PostInfinity":2,"m_RotationOrder":4}}

    Some fields have slightly more specialized context menus, e.g. Quaternion fields can copy either euler angles, or the raw quaternion:


    Or an object reference field can also copy path or the GUID:


    Scene view camera window menu can now copy/paste the camera placement (position+rotation), and the settings themselves. And again that produces just a text in clipboard, so you can send that off to someone else and they can paste into their own scene view.


    In the Animation Window, animation events can also be copied/pasted, either via keyboard shortcuts or the context menus:


    The same is for the animation clip editor in the model import settings events part:




    Let us know what you think!




    Note: a bunch of possible clipboard improvements are not made yet, for example:
    • C# APIs to copy/paste typed things into Clipboard from code,
    • Support for more SerializedProperty field types (custom structs/classes, arrays, ...)
    • Change "Copy Component" and friends to also produce text-based data in system clipboard, so you could paste that into another Unity instance, send to someone, etc.
    • Look into a hundred other places in the editor, where Copy/Paste would be needed, and add that there.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,326
    Deozaan, hippocoder, mh114 and 2 others like this.
  3. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    That's cool, thanks !
    One thing that would be really useful (I almost need it every day I'm working in Unity) is to be able to copy/paste every value of every component attached to a gameObject. (Right now you can only do it for one component :()

    Use case is, for example, trying things (mostly UI) in playmode, when you get the desired result -> right click the gameObject -> "Copy components values" -> stop playmode -> Paste

    That would be neat !
     
    DoctorShinobi likes this.
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Sounds like what you really want is a "save playmode changes" feature? :)
     
    Lars-Steenhoff, transat and Ofx360 like this.
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes, as long as clipboard contents is one of: #RGB, #RRGGBB, #RGBA, #RRGGBBAA or "Color(r,g,b,a)"
     
    Peter77 and DoctorShinobi like this.
  6. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Not necessarily, but it would be useful too ! Being able to copy an object (you actually can do that already by creating a prefab within playmode, then unpack it after) with two clicks would be great :)
     
    Kingblade likes this.
  7. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,357
    Oh wow, this finally happened :D This has been easily my top editor annoyances for years and have many times hoped Unity would implement this (can't remember how many times I've asked about this in past).

    Thank you! :)
     
  8. jbergs

    jbergs

    Joined:
    Feb 13, 2014
    Posts:
    20
    Not sure if this is part of this system but the ability to Cut/Paste keys in the Animation window and Timeline window would be awesome. I spend lots and lots of time copying > pasting > then deleting old keys.
     
  9. frarf

    frarf

    Joined:
    Nov 23, 2017
    Posts:
    27
    Are we supposed to take that as a hint? ;)
     
  10. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,357
    That apply button should be there :) like just have a way to apply the changes before you exit playmode. The copy / paste setup helps but it's tedious.

    This is something people have always struggled with Unity. In Unity 4 I worked around the lack of copy/paste by just dragging a prefab from gameobject while the game was running and then swapped the GO with the prefab once stopped the play in the editor :D

    ScriptableObjects getting more commonly used have also helped a lot.
     
  11. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I love this so much. Thanks!

    Btw when you get a chance (I know this is cheeky) but a major, major quality of life thing I added was having a back and forward shortcut. This is the same in visual studio or your browser, it would be such an instinctive and phenomenal navigation tool when you're object hopping around the project window.
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    On the list, but not related to copy/paste!
     
    Fira-Soft and hippocoder like this.
  13. SirIntruder

    SirIntruder

    Joined:
    Aug 16, 2013
    Posts:
    49
    While on this subject, any hint of copy/cut/paste of files in the project window? :) Moving a a file from folder A to folder B in big projects is quite a bit of effort currently
     
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I did try using the new Properties (context menu) feature to get a folder and not just an object in focus but it didn't work. Perhaps it could be expanded? right click a target folder and you get a neat project window pop with the top level being that folder.

    Seems slightly unusual but no less useful.

    (for now you could bookmark a folder and drag something in there - at least in theory that would work)
     
  15. SirIntruder

    SirIntruder

    Joined:
    Aug 16, 2013
    Posts:
    49
    yeah, I could also open an another project window and lock it. But in all cases I need to awkwardly navigate back and forth, instead of cut -> go to destination folder -> paste.
     
  16. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    On the topic of copy/paste, any chance copy/paste was added to the Assets (e.g. Prefabs, Materials, etc...)?
     
  17. Kingblade

    Kingblade

    Joined:
    Jan 15, 2014
    Posts:
    14
    Would love to be able to copy an entire game object hierarchy from one project to another with a simple CTR+C, CTR+V
     
    transat likes this.
  18. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Screen Shot 2020-04-22 at 10.49.02 pm (2).png


    @Aras, I'd like to right click here to paste components, rather than on the tiny vertical ellipsis.
     
    Havokki, Aras, Baste and 4 others like this.
  19. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,326
    Most GameObjects in my projects have Components attached, there is no free space to right-click in most cases, unless you search for it.

    What I think should be supported is to paste Components with the Ctrl+V shortcut. If you copied a Component, select another GameObject and press Ctrl+V, it should paste the Component to the selected GameObject. "Paste values" if a the same Component exists on the target GO already, or add the Component if it does not exist yet.

    This would allow to paste a Component without having to scroll down in the inspector to find the free space at the bottom to right-click and choose "Paste" in the context-menu.


    PS: You don't have to click the vertical ellipsis button, you can also right-click on any Component header.
     
    firstuser likes this.
  20. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,077
    Why be humble about it:

    upload_2020-4-23_10-26-33.png

    I'm all in favour about being able to right click on the empty space, but also next to the add component button and really wherever.

    Just let me throw my mouse over there and go "paste" and not have to aim would be A+++. Might be usability stuff I haven't thought about, but copy-pasting is great and having to aim to do it is lame.
     
    firstuser, Kingblade and transat like this.
  21. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I get what you're saying but as @Baste pointed out it doesn't have to be one or the other. Personally I would never use Ctrl+V as I would not be confident that I'd be pasting the component in the right place, especially considering you can have 2 inspectors open (with one locked)... a scenario which might not be so uncommon if you're copying and pasting components from one GO to another.

    PS - Didn't know I could click on any component header. Handy tip! Cheers!
     
    Peter77 and hippocoder like this.
  22. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah there can be multiple inspectors and it's not easy to figure which would be selected (like properties). Best not have keyboard shortcuts for those. Keep keyboard shortcuts for values or for scene operations.
     
  23. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,077
    ctrl+v would (probably) work on the current active window, so you'd click in the inspector you want to paste in before pasting.

    If you hit paste and you have the wrong window focused, you just ctrl+z, so it's no biggie.
     
  24. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    They'd need to increase the visibility of which inspector to use. With the new right-click properties feature, people can have a ton of these.

    Is it worth having inspectors have this highlighted border, or fading and unfading it, really worth it to support a single copy and paste keyboard shortcut?

    Especially shortcuts that are shared with other tasks. I'd say it's all possible but I wouldn't want to be the people coding the supporting work required for it or documenting it.
     
    transat likes this.
  25. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    New in 2020.2 alpha 8 related to clipboard (https://unity3d.com/unity/alpha/2020.2.0a8):
    • User-written serializable C# class & struct fields can be copy-pasted in the inspector
    • Keyboard shortcuts for "copy scene camera placement" and "paste scene camera placement" (no shortcuts are assigned by default; use shortcuts dialog)
     
  26. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,077
    @Aras, thoughts about pasting into the area below the Add Component button? Bad idea, Good idea will do it, Good idea not sure if will do it, Jury Still Out?
     
  27. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Added into a todo list, but not sure when exactly we'll get to actually do it :)
     
    Baste likes this.
  28. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    This is a real time saver @Aras

    One oddity is that if you try to use HDR with Gradient, it disables Cut & Paste

    That is, applying [GradientUsage(true)] to a gradient variable disables Cut & Paste where it normally works for a standard Gradient.
     
  29. Nick-Nexefy

    Nick-Nexefy

    Joined:
    Mar 20, 2019
    Posts:
    4
    Is there way to add this Copy/Paste support to custom inspectors in the API than you can use. Whilst you can obvious poll imgui events for a ContextClick and then show generic menu, all this would have to coded from scratch.
     
  30. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,077
    It's supported on PropertyFields, but not normal value fields. So if you have an EditorGUILayout or EditorGUI.PropertyField targeting a Vector2, you can copy-paste, but not if you have an EditorGUILayout.Vector2Field.

    You can also copy-paste entire custom classes by using EditorGUI.BeginPropery and EditorGUI.EndProperty. That only seems to mean that clicking anywhere inside the rect you have marked copies or pastes the property you passed to BeginProperty, it doesn't really relate to what data you actually draw in that space, which may be confusing if you're not aware of it.

    A shortcoming, at least in Unity 2020.3.11 is that you can't copy-paste nested properties in custom scripts. So this doesn't let me copy-paste between the two fields:
    Code (csharp):
    1. EditorGUILayout.PropertyField(d1.FindPropertyRelative("a"));
    2. EditorGUILayout.PropertyField(d2.FindPropertyRelative("a"));
    So it's as far as I can tell only possible to copy-paste entire fields on the serializedObject.
     
  31. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,480
    How can I copy gradient field's gradient to clipboard via code, so that it can be pasted in regular gradient fields like e. g. the particle system has?

    Use case: I have a Gradient object which I'd like to modify via C# code and then have it put into the clipboard so that I can use it e. g. for a fire particle.
     
  32. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,326
    I exclusively worked with Unity 2019.4 for the last two years and just switched recently to 2021.2 to start a new project.

    202x.x introduced a severe workflow regression in terms of copy/paste the Transform component.

    You're no longer able to copy and paste the Transform component without crawling through sub-menus, which uses more mouse-movement, more clicks and thus more time and focus. That's an extremely inconvenient change.

    Please bring back the "Copy Component" and "Paste Component" items to the root context menu.

    upload_2022-1-1_16-39-52.png


    upload_2022-1-1_16-39-57.png
     
    Michal_Stangel, firstuser and Rowlan like this.
  33. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,480
    With emphasis on severe. The submenu-hoops are a huge waste of everyones time.
     
    firstuser likes this.
  34. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,480
    It's pretty much redundant anyway since you can copy/paste the explicit position / rotation / scale values by clicking on the label:

    cp.png

    Imo it should revert back to Copy Component and in addition to that Position popup menu should get a Copy Position (World) like it's in the sub-menu of the Copy menu item of the transform.
     
  35. Flamacore

    Flamacore

    Joined:
    Dec 17, 2013
    Posts:
    133
    I'm trying to come up with a little context menu item to merge a copied list from a component with another one but how do I go about deserializing the copied data? Right now, JsonUtility throws errors for that. It's a GenericPropertyJSON which I assume points to my custom class.

    I can already copy and paste the list by hand but I want a merge instead. Any leads you can guide me to?
     
  36. HernandoNJ

    HernandoNJ

    Joined:
    May 13, 2018
    Posts:
    75
  37. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    9,110
    Please stop spamming the forums with this post. This is the 5th identical post you've made with this.
     
  38. HernandoNJ

    HernandoNJ

    Joined:
    May 13, 2018
    Posts:
    75
    You're right, but there are 5 or more posts with a similar question. So, if there would be just 1 post with that question, I'd post that answer just 1 time.
     
  39. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    9,110
    There are thousands of posts on (say) a NullReferenceException, it doesn't mean if you had something to say about this issue you'd post on all of them. I would recommend using the latest one only or only posting to a few recent ones at best.

    It's good to help but some of your posts were also necroing old posts too. Note that your posts were reported multiple times. Here's the Community Code of Conduct.
     
    HernandoNJ likes this.
  40. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,751
    As this thread is quite old, I'm locking the thread. If anyone wants to continue the conversation, please create a new thread.
     
    HernandoNJ likes this.
Thread Status:
Not open for further replies.