Question by 
               robby702 · Sep 07, 2020 at 06:53 PM · 
                layoutpropertydrawerobjectfield  
              
 
              PropertyDrawer ObjectField layout issue when part of property containing multiple elements
When creating a property with a single object field the layout is fine:  (x position = 0, width = property width)
 (x position = 0, width = property width) 
When creating a property with more elements the object field does not scale down as expected:  (x position = 0, width = property width * 0.4f)
 (x position = 0, width = property width * 0.4f) 
Is it possible to remove the gap between the element name and the object selection field?
Here is the code for the second image:
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
         {
             EditorGUI.BeginProperty(position, label, property);
 
             float totalWidth = position.width;
             Rect objectRect = new Rect(
                 position.x,
                 position.y,
                 position.width * 0.4f,
                 position.height);
 
             Rect buttonRect = new Rect(
                 position.x + position.width * 0.5f,
                 position.y,
                 position.width * 0.2f,
                 position.height);
 
             Rect nameRect = new Rect(
                 position.x + position.width * 0.7f,
                 position.y,
                 position.width * 0.4f,
                 position.height);
 
             EditorGUI.ObjectField(objectRect, property);
 
             if (GUI.Button(buttonRect, "Search"))
             {                    
                 Debug.Log("Button Press");
             }
 
             EditorGUI.LabelField(nameRect, "some string");
             EditorGUI.EndProperty();
     }
 
                 
                editor2.png 
                (5.5 kB) 
               
 
                
                 
                editor.png 
                (4.6 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
How to place a property underneath some other properties (property drawer of serialized object)? 1 Answer
UI layout suddenly changed, not sure how to get it back 0 Answers
How to make Grid Layout Buttons in Custom Editor Window? 2 Answers
How to make child of layout group always fit the screen size and be placed side by side? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                