docs.unity3d.com
Search Results for

    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;
    }
    
    ```
    
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)