Custom Inspector not showing anything

Hi. I have a flocking algorithm that uses different behaviours such as Cohesion, Avoidance etc. to help them stay in groups. I have tried to design a custom editor following this video : Flocking Algorithm in Unity, Part 6: Composite Behavior Custom Editor - YouTube

Although it is outdated, I have tried to adapt the code to use today’s syntax. I believe I have changed everything necessary that is outdated, however I am confused as to why the inspector is still blank, as I set my label fields up how I thought they were supposed to be. My best guess is I have used GUIUtility.ExitGUI();, or EditorGUILayout.Begin(and end)Horizontal();s wrongly. Here is the full code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Add this namespace to give access to the custom editor attribute
using UnityEditor;

// This attribute only works with the namespace 'UnityEditor'
[CustomEditor(typeof(CompositeBehaviour))]
// Inherits from Editor instead of Monobehaviour
public class CompositeBehaviourEditor : Editor
{

    public override void OnInspectorGUI()
    {
        #region Setup
        // Here we cast target, this is an object (in the inspector), directly to composite behaviour so we can access it's variables etc.
        CompositeBehaviour cb = (CompositeBehaviour)target;

        // Gives us a box in the inspector
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.EndHorizontal();
        #endregion


        // Check for behaviours
        // If there are no behaviours or the array is empty
        if (cb.behaviours == null || cb.behaviours.Length == 0)
        {
            EditorGUILayout.HelpBox("No behaviours in array.", MessageType.Warning);
            // Move cursor:
            EditorGUILayout.EndHorizontal();
            GUIUtility.ExitGUI();
        }
        else
        {
            // If there are behaviours (whole reason of this script!)
            EditorGUILayout.BeginHorizontal();
            // Each one of these simple creates a label field with a min width and max width
            // These two widths mean that even if the inspector window is resized, the text will remain where we it want
            EditorGUILayout.LabelField("Number", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f));
            EditorGUILayout.LabelField("Behaviours", GUILayout.MinWidth(60f));
            EditorGUILayout.LabelField("Weights", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f));
            EditorGUILayout.EndHorizontal();
            

            // Set save checker
            EditorGUI.BeginChangeCheck();

            // Display each behaviour:
            for (int i = 0; i < cb.behaviours.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                // Make each item a string
                EditorGUILayout.LabelField(i.ToString(), GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f));
                // Show a field for the behaviours
                // False means we wont take any objects that come from the scene - we wont only scriptable objects
                cb.behaviours _= (FlockBehaviour)EditorGUILayout.ObjectField(cb.behaviours*, typeof(FlockBehaviour), false, GUILayout.MinWidth(60f));*_

// Do the same for the weights:
cb.weights = EditorGUILayout.FloatField(cb.weights*, GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f));*
EditorGUILayout.EndHorizontal();
// This fixes the error '
GUIUtility.ExitGUI();
}

// Check if anything has changed
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(cb);

}

}

// Clear inspector
EditorGUILayout.EndHorizontal();

if (GUI.Button(new Rect(30, 30, 30, 30), “Add Behaviour”))
{
// Add behaviour
AddBehaviour(cb);
// Let Unity know this scriptable object has been changed and needs to be saved
EditorUtility.SetDirty(cb);

}

// We only want the add button to appear if there are behaviours to remove
if (cb.behaviours != null && cb.behaviours.Length > 0)
{
if (GUI.Button(new Rect(10, 10, 10, 10), “Remove Behaviour”))
{
// Remove behaviour
RemoveBehaviour(cb);
// Let unity know this scriptable object has been changed and needs to be saved
EditorUtility.SetDirty(cb);

}
}

}

void AddBehaviour(CompositeBehaviour cb)
{
// Get original size of the array
int oldCount = (cb.behaviours != null) ? cb.behaviours.Length : 0;
// If array is empty we will start with 1 item
FlockBehaviour[] newBehaviours = new FlockBehaviour[oldCount + 1];
// Create new array
float[] newWeights = new float[oldCount + 1];
// Iterate through and add the original values
for (int i = 0; i < oldCount; i++)
{
newBehaviours = cb.behaviours*;*
newWeights = cb.weights*;*

}
// newWeights can’t be zero otherwise new behaviours can’t take effect
// The user would think something has gone wrong if we don’t set it to 1f:
newWeights[oldCount] = 1f;
cb.behaviours = newBehaviours;
cb.weights = newWeights;
}

void RemoveBehaviour(CompositeBehaviour cb)
{
// We know the array wont be null, as the button would not appear
int oldCount = cb.behaviours.Length;

// If there is only one behaviour, we can just clear it out:
if (oldCount == 1)
{
cb.behaviours = null;
cb.weights = null;
return;

}

// If array is empty we will start with 1 item
FlockBehaviour[] newBehaviours = new FlockBehaviour[oldCount - 1];
// Create new array
float[] newWeights = new float[oldCount - 1];
// Iterate through and add the original values
for (int i = 0; i < oldCount - 1; i++)
{
newBehaviours = cb.behaviours*;*
newWeights = cb.weights*;*

}
// We do not need to assign anything to newWeights here because it has already been assigned
cb.behaviours = newBehaviours;
cb.weights = newWeights;
}

}
Thanks in advance for any suggestions.

Your guess is right. Do not use ExitGUI unless you really have to and you know what it actually does. There are almost no reasons to ever use ExitGUI at all. All this method does is artificially throw a GUIExitException which will immediately terminate any further processing of your GUI code. This method is only required in some rare cases. First of all it should only be called in response to a user input event. Calling it during the layout or the repaint event just makes no sense. It’s meant to state that during this event handling you might have modified the state of your GUI so it’s impossible to continue processing. This is the case when you open another editor window from within the OnGUI / OnInspectorGUI or another editorwindow. Though you only “open” a new window on a button click or keypress.

Since you already use an if - else statement you could simply remove the ExitGUI call completely. If for some reason you really want to completely terminate any further processing you usually just use a simple return statement. However in your case that doesn’t seem to make any sense. You have an Add Behaviour button at the end of your code. You would never reach that code unless you have behaviours.