How can I set position of a GUI.Button in Inspector ?

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

    [CustomEditor(typeof(ConversationTrigger))]
    public class ConversationTriggerEditor : Editor
    {
        private ConversationTrigger conversationtrigger;
    
        private void OnEnable()
        {
            conversationtrigger = FindObjectOfType<ConversationTrigger>();
        }
    
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
    
            if(GUI.Button(new Rect(0.1f,0.5f,0.1f,0.1f), "Add new item"))
            {
                conversationtrigger.conversations.Add(new Conversation());
            }
    
            if (GUILayout.Button("Save Conversations"))
            {
                conversationtrigger.SaveConversations();
            }
    
            if (GUILayout.Button("Load Conversations"))
            {
                Undo.RecordObject(conversationtrigger, "Loaded conversations from JSON");
                conversationtrigger.LoadConversations();
            }
        }
    }

I tried this line :

if(GUI.Button(new Rect(0.1f,0.5f,0.1f,0.1f), "Add new item"))

But that make the button vanished like deleted.
If I’m using GUILayout.Button I will see the button but then I can’t set the button position so I’m using GUI.Button.

I want to position the button “Add new item” before the Canvas and always after the last conversation item in this case the Locked Room and if I will add a new item the button should be stay after the new added item and before the Canvas.

I guess this values of the Rect are wrong making the button to be positioned out of the window.

This is a screenshot of the Inspector :

138351-buttons1.jpg

@dubiduboni_unity

To mix custom GUI with default GUI, you will need to add each GUI element manual (i.e. not with DrawDefaultInspector()) in the order you want them to appear, using GUI elements such as ObjectField and Toggle.


This will be a bit of a hassle to get it to look just the way you want it. Alternatively, you could draw the Add New button before the DrawDefaultInspector() call to always draw the button at the top, or don’t draw the button at all, and just increase the Conversation’s Size int when you want to add another Conversation.