ValueInput with a struct and a custom inspector

Hello.

I am trying to make a ValueInput use a struct and show a custom inspector – pretty much just like how a Vector3 is displayed:

In ValueInput, there is a SupportsDefaultValue method that seems to control if an inspector will show. It matches against a set of types:

        private static readonly HashSet<Type> typesWithDefaultValues = new HashSet<Type>()
        {
            typeof(Vector2),
            typeof(Vector3),
            typeof(Vector4),
            typeof(Color),
            typeof(AnimationCurve),
            typeof(Rect),
            typeof(Ray),
            typeof(Ray2D),
            typeof(Type),
#if PACKAGE_INPUT_SYSTEM_EXISTS
            typeof(UnityEngine.InputSystem.InputAction),
#endif
        };

        public static bool SupportsDefaultValue(Type type)
        {
            return
                typesWithDefaultValues.Contains(type) ||
                typesWithDefaultValues.Contains(Nullable.GetUnderlyingType(type)) ||
                type.IsBasic() ||
                typeof(UnityObject).IsAssignableFrom(type);
        }

If I use a struct, then the inspector will not show:

    public struct LampIdValue
    {
        public string id;
        public int value;

        public static readonly LampIdValue Empty = new LampIdValue { id = string.Empty, value = 0 };
    }
.
.
.
var lampIdValue = ValueInput<LampIdValue>("Lamp ID " + (i + 1), LampIdValue.Empty);

So, the only way I can get the inspector to show is to make the ValueInput use a UnityObject:

    [Serializable]
    public class LampIdValue : UnityObject
    {
        public string id;
        public int value;

        public static readonly LampIdValue Empty = new LampIdValue { id = string.Empty, value = 0 };
    }
.
.
.
var lampIdValue = ValueInput<LampIdValue>("Lamp ID " + (i + 1), LampIdValue.Empty);

Now the problem is, whenever I restart Unity, (or make a code change), the data is lost:

7882264--1002781--Screen Shot 2022-02-08 at 4.59.01 PM.png

Does anyone know why the data is not being preserved?

I’m poorly versed in the land of custom nodes, but did you try decorating your struct with [Serializable] attribute? I recall that being a requirement for structs to display correctly within UnityVS Variables inspector. Might also help here.

@PanthenEye - thanks, but we tried that. Unfortunately, the inspector wont show because of how they lock it down to just a few types (Vector2, Vector3, Vector4, Color, AnimationCurve, Rect, Ray, Ray2D, primitives, etc).