CustomPropertyDrawer for System.Guid doesn't show up

I am trying to create a property drawer for System.Guid, which does have the [Serializable] attribute.

However, public or [SerializeField] fields still do not show up for fields of type System.Guid.

This is my code for the property drawer:

using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

[CustomPropertyDrawer(typeof(Guid))]
public class GuidDrawer : PropertyDrawer
{
    private VisualElement root;
    private VisualTreeAsset template;

    public override VisualElement CreatePropertyGUI(SerializedProperty property)
    {
        root = new VisualElement();
        template = ElementAssets.Template.LoadAsset();
        template.CloneTree(root);
        Debug.Log("CustomPropertyDrawer Enabled!");
        return root;
    }
}

Yet, when I select an object who has a component who has a [SerializeField] Guid field, it just doesn’t show up. No errors or other messages in the console either.

The docs only state that the type for custom property drawers must have the [Serializable] attribute, which System.Guid does. Is there something else I’m missing?

Custom property drawers only customize the UI, they don’t affect what the serialization system supports. System.Guid is not supported by the Unity serializer and adding a custom property drawer won’t change this.

The usual rules for what is supported by the serializer do not apply to the .Net API. Only the types explicitly mentioned are supported (primitives, enums, arrays, lists).

You have to convert the System.Guid to something Unity can serialize and then you can also create a custom property drawer for it.

I found an instance where Unity has done this themselves, converting it to a byte array:

Instead of a component, you could also use a serializable struct that more directly converts to System.Guid, by implementing implicit conversion operators.

1 Like