Search Unity

Feature Request Editor scene objects pipette

Discussion in 'Editor & General Support' started by IAndrewNovak, Oct 17, 2022.

  1. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Hi. Could we have a nice editor scene objects pipette in order to fill script properties easily?

    It's so convinient feature for devs who work with large scenes.
    I have attached the example video where that pipette is used.

     
    joan_stark and marcuslelus like this.
  2. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,427
    i guess it would also need highlighting current mouse over target,
    so that user knows what object is going to get picked?

    and somehow need to pick objects under object objects too..(which is quite difficult in unity scene editor currently, it seems to pick all kind of objects, until you get the correct one after 10 clicks..)
     
  4. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Wow. Nice ideas!
     
  5. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Any news about this must-have feature from Unity dev?
     
  6. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Bump. Must-have feature for scenes with many game objects and parents
     
  7. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
  8. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    331
    Hello IAndrewNovak, thanks for making the feature request. To make sure I'm capturing this properly, essentially you'd want an alternate way for the Object Picker to select an object, which would allow you simply select it from the scene?

    In the future, I'd recommend using our public roadmap for submitting feature requests, that way it ends up directly in our inbox.

    Cheers.
     
  9. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Hi Benoitd. Thanks for your reply ^_^

    Yes, you are right. I strongly need the possibility to fill up the script properties by clicking objects in the scene.

    I have more than 1000 game objects in the scene. Many of them have separate parents and are so hard to find and fill scripts properties by drag and drop or find by name. The pipette will be so much help for me and the Unity community.

    Have a nice day.
     
  10. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Hi benoitd_unity
    Any news about this feature from Unity Team?
    Also I send a feature info via roadmap
     
    Last edited: Aug 10, 2023
  11. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
  12. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,439
    @IAndrewNovak , there's no purpose in bumping this every few days or weeks. New features flow into the pipeline and can take a year or two, because they have a backlog of other priorities.

    @benoitd_unity , Unity has never been particularly clear, or rather I should say has often been quite contradictory, about where people should submit feature requests. "Just post them on the forum, we read those." "Put them on the roadmap." "Vote on what is important to you because we have no idea how to prioritize since we don't dogfood." You need a much more obvious and official page labeled ADD YOUR FEATURE REQUESTS HERE, and moreso, you need to back that up with commentary and clarity on what will be done.
     
  13. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,908
    I've 100% seen editor tools out there that do this, though I can't find it with a quick search. I know I've seen youtube vids with folks using this as part of their editor toolbox.
     
  14. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Thanks guys for the reply.
    I bumped this post while this super cool feature not available in Unity for me and other Unity community.
    If you used a pipette at last once in other apps, you understand why I want to implement this on the native side of Unity
     
  15. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Any news?
     
  16. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
  17. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,908
    Bumping this thread doesn't do anything mate. The forums are not for feature requests.

    I'm 100% sure assets for this exist out there as well, or you can implement this yourself. That's going to be the faster option than waiting for Unity to do it. Make it yourself and move on.
     
  18. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Hi. Forum for feature requests (check available tags in the title). I can't make this tool, but if I could, I want the Unity team to give such a beautiful tool to the whole community.

    Instead of contradicting me, I would appreciate your support. I do it not for myself but for everyone
     
  19. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,908
    The tag is there from the days of yore. The Unity devs seldom if ever do feature requests through the forum anymore.

    I attempted to make this before but didn't have any luck. After a good amount of research I did manage to get something working nicely without any real hacks.

    First, your little attribute:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. namespace LBG.EditorUtils
    3. {
    4.    using System;
    5.    using UnityEngine;
    6.  
    7.    /// <summary>
    8.    /// Apply this attribute to <see cref="GameObject"/> and <see cref="Component"/> fields
    9.    /// to be able to pick them from the scene.
    10.    /// </summary>
    11.    [System.Diagnostics.Conditional("UNITY_EDITOR")]
    12.    [AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
    13.    public sealed class ScenePipetteAttribute : PropertyAttribute { }
    14. }
    And then the actual property drawer:
    Code (CSharp):
    1. namespace LBG.EditorUtils.Editor
    2. {
    3.     using System;
    4.     using UnityEngine;
    5.     using UnityEditor;
    6.     using UnityEngine.UIElements;
    7.  
    8.     [CustomPropertyDrawer(typeof(ScenePipetteAttribute))]
    9.     internal sealed class ScenePipettePropertyDrawer : PropertyDrawer, IDisposable
    10.     {
    11.         #region Internal Members
    12.  
    13.         private Type _propertyType = null;
    14.         private bool _pipetteMode = false;
    15.  
    16.         private bool _isGameObjectType = false;
    17.         private bool _isComponentType = false;
    18.  
    19.         private EventCallback<MouseDownEvent> _onMouseDown;
    20.         private SerializedProperty _property;
    21.  
    22.         private readonly GUIContent _buttonContent;
    23.         private readonly Texture2D _pipetteTexture;
    24.  
    25.         #endregion
    26.  
    27.         #region Constructor
    28.  
    29.         public ScenePipettePropertyDrawer() : base()
    30.         {
    31.             _pipetteTexture = (Texture2D)EditorGUIUtility.Load("d_color_picker");
    32.             _buttonContent = new GUIContent(_pipetteTexture);
    33.         }
    34.  
    35.         #endregion
    36.  
    37.         #region Property Drawer Overrides
    38.  
    39.         public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    40.         {
    41.             return 0f;
    42.         }
    43.  
    44.         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    45.         {
    46.             Event e = Event.current;
    47.  
    48.             // have to do this during layout as field info/serialized property
    49.             // aren't available before hand
    50.             if (e.type == EventType.Layout)
    51.             {
    52.                 var fieldInfo = this.fieldInfo;
    53.                 _propertyType = fieldInfo.FieldType;
    54.                 _isGameObjectType = typeof(GameObject).IsAssignableFrom(_propertyType);
    55.                 _isComponentType = typeof(Component).IsAssignableFrom(_propertyType);
    56.             }
    57.  
    58.             if (_pipetteMode == true && e.keyCode == KeyCode.Escape)
    59.             {
    60.                 this.ExitPipetteMode();
    61.             }
    62.  
    63.             if (property.propertyType != SerializedPropertyType.ObjectReference)
    64.             {
    65.                 EditorGUILayout.PropertyField(property, label);
    66.                 return;
    67.             }
    68.  
    69.             if (_isGameObjectType == false && _isComponentType == false)
    70.             {
    71.                 EditorGUILayout.PropertyField(property, label);
    72.                 return;
    73.             }
    74.  
    75.             using (new EditorGUILayout.HorizontalScope())
    76.             {
    77.                 Color c = GUI.color;
    78.                 GUI.color = _pipetteMode ? Color.yellow : c;
    79.  
    80.                 EditorGUILayout.ObjectField(property);
    81.  
    82.                 if (GUILayout.Button(_buttonContent, GUILayout.MaxWidth(22f)))
    83.                 {
    84.                     this.EnterPipetteMode(property);
    85.                 }
    86.  
    87.                 GUI.color = c;
    88.             }
    89.         }
    90.  
    91.         #endregion
    92.  
    93.         #region Internal Methods
    94.  
    95.         private void EnterPipetteMode(SerializedProperty property)
    96.         {
    97.             _pipetteMode = true;
    98.             _property = property;
    99.             _onMouseDown = new EventCallback<MouseDownEvent>(HandleSceneViewMouseClick);
    100.  
    101.             SceneView.duringSceneGui += HandleSceneGUI;
    102.             foreach (SceneView sv in SceneView.sceneViews)
    103.             {
    104.                 sv.rootVisualElement.RegisterCallback(_onMouseDown, TrickleDown.NoTrickleDown);
    105.             }
    106.         }
    107.  
    108.         private void HandleSceneViewMouseClick(MouseDownEvent e)
    109.         {
    110.             Vector3 mousePos = e.originalMousePosition;
    111.             var po = HandleUtility.PickGameObject(mousePos, true);
    112.  
    113.             if (po != null)
    114.             {
    115.                 if (_isGameObjectType == true)
    116.                 {
    117.                     _property.objectReferenceValue = po;
    118.                 }
    119.                 else if (_isComponentType == true)
    120.                 {
    121.                     if (po.TryGetComponent(_propertyType, out Component component))
    122.                     {
    123.                         _property.objectReferenceValue = component;
    124.                     }
    125.                 }
    126.  
    127.                 _property.serializedObject.ApplyModifiedProperties();
    128.             }
    129.  
    130.             this.ExitPipetteMode();
    131.         }
    132.  
    133.         private void HandleSceneGUI(SceneView sceneView)
    134.         {
    135.             // this prevent selection in the scene while pipette mode is active
    136.             int id = GUIUtility.GetControlID(FocusType.Passive);
    137.             HandleUtility.AddDefaultControl(id);
    138.         }
    139.  
    140.         private void ExitPipetteMode()
    141.         {
    142.             _pipetteMode = false;
    143.             SceneView.duringSceneGui -= HandleSceneGUI;
    144.             foreach (SceneView sv in SceneView.sceneViews)
    145.             {
    146.                 sv.rootVisualElement.UnregisterCallback(_onMouseDown);
    147.             }
    148.         }
    149.  
    150.         void IDisposable.Dispose()
    151.         {
    152.             if (_pipetteMode == true)
    153.             {
    154.                 this.ExitPipetteMode();
    155.             }
    156.         }
    157.  
    158.         #endregion
    159.     }
    160. }
    161. #endif
    And the tool in action: https://i.gyazo.com/7cb85d4beeffe05e7b267424e37de909.mp4

    There's a certain sense of irony of an IMGUI drawer using UI toolkit to handle part of it's functionality. This was done on 2022.3.12f1.

    Edit: I will add that the IDisposable support only works from this version onwards as well.

    Certainly a lot that could be improved upon. Would like to change the cursor but the pipette texture isn't set up for it (maybe a way to draw the texture near the cursor?). I certainly would like to open the floor to any and all suggestions.

    If I improve upon it I'll pose some updates. Maybe make a repo out of it.
     
    Last edited: Nov 1, 2023
    mgear likes this.
  20. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    I disagree. Tags are useful and I see how the Unity team reacts.
    Also, I sent the feature request via RoadMap too.

    Thanks. That works perfectly! I found an issue with the show override property no as Bold for prefab.

    Door - is pipette property. Display - default

    upload_2023-10-31_15-13-56.png
     
  21. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,908
    Not sure why that's happening on your end. For me it works without any additional code:
    upload_2023-11-1_18-43-17.png

    I forgot to mention it before, but I will stress that the property drawer has the potential to not work properly on any version before 2022.2.12f1 or 2023.2.0b15, being the version where
    IDisposable
    support was added for property drawers (Thank you for doing that Unity). Not sure what other Unity versions are getting that addition.

    Versions before this could potentially run issues due to not being cleaned up correctly.
     
  22. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
    Thanks for the info.

    I forgot to write a Unity version. I used and tested in 2023.1.18 and 2023.1.19
     
  23. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118
  24. IAndrewNovak

    IAndrewNovak

    Joined:
    Nov 29, 2013
    Posts:
    118