How to create list with Struct Elements in Custom Inspector

Hello everyone. I’m trying to create a custom inspector that has a List and inside this list contains elements where each element is a serializable struct that I defined. So for example, I will define a public Serializable struct called TransformSpawnPoints which contains 2 properties: the transformSpawnPoint and the initial velocity that it has. I will then define a list whose type is this struct. I removed all the functionality that doesn’t pertain to my question for complexity sake. Here is the bare bones version of what my class looks like:

ObstacleSpawnee Class:

using System;
using System.Collections.Generic;
using UnityEngine;

public class ObstacleSpawnee : MonoBehaviour
{
    //Inspector
    [SerializeField] [HideInInspector]
    private List<TransformSpawnPoints> _possibleTransformSpawnPoints;
}
[Serializable]
public struct TransformSpawnPoints
{
    [SerializeField]
    private Transform transformSpawnPoint;
    [SerializeField]
    public Vector2 initialVelocity;
}

This will create a list where each element should have the transformSpawnPoint and initial velocity properties. Without a custom inspector this works fine and it looks like this.
7616284--946663--SpawneeSpawnPoint2.PNG

The issue is I want to be able to do this in a custom inspector because I want to add a few tweaks that wouldn’t be possible without it. However, when I try to do this using a custom inspector the list still shows up, but the serializable public struct I created is ignored and it just shows me a list of blank elements that I’m unable to modify. It looks like this:
7616284--946651--SpawneeSpawnPoint1.PNG

Can somebody explain to me why the custom inspector is unable to see this struct and how I would go about resolving this? My custom inspector code is shown below. Thanks

ObstacleSpawnee_Editor Class:

using UnityEditor;

#if UNITY_EDITOR
[CustomEditor(typeof(ObstacleSpawnee))]
public class ObstacleSpawnee_Editor : Editor
{
    private SerializedProperty possibleTransformSpawnPoints;
    void OnEnable()
    {
        possibleTransformSpawnPoints = serializedObject.FindProperty("_possibleTransformSpawnPoints");
    }

    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(possibleTransformSpawnPoints);
        serializedObject.ApplyModifiedProperties();
    }
}
#endif
1 Like

I would love to know this as well, I’ve been struggling with it for a while. I can’t get EditorGUI.PropertyField() to display anything at all for any struct that doesn’t have a custom property drawer implemented. Even just a single one, not even in a list. Am I missing something obvious? I’ve been googling for ages and trying everything I can think of.

[edit] Aaand just solved it. For root level structs and basic tests my issue was that I was testing on fields marked [HideInInspector], which I didn’t realise would affect manual property drawing. For the more complicated custom property drawer, I needed to tell it to draw children when expanded. Oops.