Why is the Header attribute not shown in the Inspector?

using UnityEngine;
using UnityEditor;

namespace BezierSolution.Extras
{
    [CustomEditor( typeof( BezierSpline ) )]
    [CanEditMultipleObjects]

    public class BezierSplineEditor : Editor
    {
        internal BezierSpline[] allSplines;

        public static BezierSplineEditor ActiveEditor { get; private set; }

        [Header("Randomize")]
        int randomize = 0;

        private void OnEnable()
        {
            Object[] splines = targets;
            allSplines = new BezierSpline[splines.Length];
            for( int i = 0; i < splines.Length; i++ )
            {
                BezierSpline spline = (BezierSpline) splines[i];
                if( spline )
                    spline.Refresh();

                allSplines[i] = spline;
            }

            ActiveEditor = this;

            if( BezierUtils.QuickEditSplineMode )
            {
                Tools.hidden = true;

                EditorApplication.update -= SceneView.RepaintAll;
                EditorApplication.update += SceneView.RepaintAll;
            }

            Undo.undoRedoPerformed -= OnUndoRedo;
            Undo.undoRedoPerformed += OnUndoRedo;
        }

        private void OnDisable()
        {
            ActiveEditor = null;
            Tools.hidden = false;

            Undo.undoRedoPerformed -= OnUndoRedo;
            EditorApplication.update -= SceneView.RepaintAll;
        }

        private void OnSceneGUI()
        {
            BezierSpline spline = (BezierSpline) target;
            BezierUtils.DrawSplineDetailed( spline );

            for( int i = 0; i < spline.Count; i++ )
                BezierUtils.DrawBezierPoint( spline[i], i + 1, false );

            if( BezierSettings.ShowEvenlySpacedPoints )
                BezierUtils.DrawSplineEvenlySpacedPoints( spline );

            if( BezierUtils.QuickEditSplineMode )
            {
                // Execute quick edit mode's scene GUI only once (otherwise things can get ugly when multiple splines are selected)
                if( spline == allSplines[0] )
                {
                    BezierUtils.QuickEditModeSceneGUI( allSplines );
                    HandleUtility.AddDefaultControl( 0 );
                }

                return;
            }
        }

        public override void OnInspectorGUI()
        {
            BezierUtils.DrawSplineInspectorGUI(allSplines);
        }

        private void OnUndoRedo()
        {
            for( int i = 0; i < allSplines.Length; i++ )
            {
                if( allSplines[i] )
                {
                    allSplines[i].dirtyFlags |= InternalDirtyFlags.All;
                    allSplines[i].Refresh();
                }
            }

            Repaint();
        }

        private bool HasFrameBounds()
        {
            return !serializedObject.isEditingMultipleObjects;
        }

        private Bounds OnGetFrameBounds()
        {
            return new Bounds( ( (BezierSpline) target ).transform.position, new Vector3( 1f, 1f, 1f ) );
        }
    }
}

Because the int randomize = 0; is private.
You need to make it either public or use [SerializeField]

Edit: Though this is a custom editor for a given type.
Anything you want to draw should be in the OnInspectorGUI (IMGUI) or CreateInspectorGUI() (UI Toolkit)

1 Like

We’re also looking an UnityEditor.Editor class. Serialising fields in one won’t do anything to draw it in the inspector.

Serializing a field INSIDE an inspector/editor seems fairly pointless anyhow…

There is sometimes a reason to do it. Editor/EditorWindow’s are scriptable objects, so you could serialise data into them, and access their serialised property for drawing editor fields, such as with an EditorGUI.PropertyField.

Doesn’t often come up, but it was an answer I provided to someone’s question only a month or two back (though in the context of an EditorWindow.)

It was probably flagged as spam because you’re replying a 2 year old post in order to provide irrelevant information. OP didn’t have any properties in their code.

The problem was that they were applying the attribute to editor code, which didn’t make any sense. That was already discussed and solved. There was no reason to add any more information to the thread. Necroposting is against the CoC.

1 Like