Add the Inspectable attribute to a custom type
If you have access to the source code for a custom type, add the [Inspectable]
attribute to its fields and classes. The [Inspectable]
attribute makes these fields and classes accessible to the Inspector window in the Unity Editor. You don't need to create a custom PropertyDrawer as Unity generates a basic UI for the custom type.
For more information about how to use custom types in Visual Scripting, see Use a custom type or Custom types
To add the [Inspectable]
attribute to the source code for a custom type:
Double-click the C# file. Unity opens the file in the program you specified in your preferences, under External Script Editor.
Note
For more information on script editors in Unity, see the Integrated development environment (IDE) support in the Unity User Manual.
In your external editor, on a line above your
public class
definition, add the[Inspectable]
attribute.On a line above the properties you want to have available in the Unity Inspector, add the
[Inspectable]
attribute.Follow the process described in Configure project settings to regenerate your Node Library.
The following is an example of a public class, with fields name
and amount
that are accessible and can be modified through Unity's Inspector window.
```csharp
using System;
using UnityEngine;
using Unity.VisualScripting;
[Inspectable]
public class MyClass
{
[Inspectable]
public string name;
[Inspectable]
public int amount;
public string dontShowThis;
}
```