title: Unity custom inspector which allows selected child objects
body: <p>I'm trying to make a custom inspector for a <code>PlayerInventory</code> class.  The <code>PlayerInventory</code> class consists of a list of items (which are <code>ScriptableObjects</code>), along with a quantity of each item, like this:</p>
  
  <pre><code>public class Item : ScriptableObject
  {
     public string description;
     public Sprite picture;
  }
  
  public class InventoryItem : ScriptableObject
  {
     // A reference to the Item object that contains the item's description, 
     // picture, stats, etc.
     public Item item;
  
     // The quantity of this item that the player has in his inventory
     public int quantity;
  }
  
  [CreateAssetMenu(menuName = "Player/Player Inventory")]
  public class PlayerInventory : ScriptableObject
  {
     // The list of each distinct item that the player has in his inventory,
     // along with the quantity of each item
     public List&lt;InventoryItem&gt; items;
  }
  </code></pre>
  
  <p>I created an instance of <code>PlayerInventory</code> as a game asset.  By default, the Inspector shows a list of <code>InventoryItem</code>s.  However, what I want is for the Inspector to show each <code>InventoryItem</code> element with a field to select an <code>Item</code> for it, a field to enter a quantity, and a "delete" button.  </p>
  
  <p>Here's a visual example of what I'm trying to achieve, along with my current code below.  The problem with this screenshot is that Unity is making me select an <code>InventoryItem</code> object for each element.  I want to be able to select an <code>Item</code> object for each element.  The second problem I'm having is I don't know how to set an <code>EditorGUILayout.TextField</code> to the <code>InventoryItem.quantity</code> property because I don't know how to convert the <code>SerializedProperty</code> to an <code>InventoryItem</code> object.</p>
  
  <p><a href="https://i.stack.imgur.com/qsM10.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qsM10.png" alt="enter image description here"></a></p>
  
  <pre><code>[CustomEditor(typeof(PlayerInventory))]
  public class PlayerInventoryEditor : Editor
  {
     public override void OnInspectorGUI()
     {
         this.serializedObject.Update();
  
         SerializedProperty items = this.serializedObject.FindProperty("items");
         for (int i = 0; i &lt; items.arraySize; i++)
         {
             EditorGUILayout.BeginHorizontal();
             EditorGUILayout.LabelField("Item", GUILayout.Width(50));
  
             // I don't know how to make this line reference the child "item"
             // field of the current InventoryItem
             EditorGUILayout.PropertyField(items.GetArrayElementAtIndex(i), GUIContent.none, GUILayout.Width(170));
  
             EditorGUILayout.LabelField("    Quantity", GUILayout.Width(80));
  
             // I don't know how to set the text field to the "quantity" field
             // of the current InventoryItem
             EditorGUILayout.TextField("0", GUILayout.Width(50));
  
             EditorGUILayout.LabelField("", GUILayout.Width(20));
             GUILayout.Button("Delete Item");               
             EditorGUILayout.EndHorizontal();
         }
  
         GUILayout.Button("Add Item");
     }
  }
  </code></pre>