docs.unity3d.com
    Show / Hide Table of Contents

    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:

    1. 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.

    2. In your external editor, on a line above your public class definition, add the [Inspectable] attribute.

    3. On a line above the properties you want to have available in the Unity Inspector, add the [Inspectable] attribute.

    4. 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;
    }
    
    ```
    
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023