Search Unity

Question How to add a parameter to a custom node, like a toggle?

Discussion in 'Visual Scripting' started by Leyren, Jun 3, 2023.

  1. Leyren

    Leyren

    Joined:
    Mar 23, 2016
    Posts:
    29
  2. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    84
    Hello there!

    You need to use the [Inspectable, UnitHeaderInspectable] attributes.

    upload_2023-6-3_21-14-49.png


    Code (CSharp):
    1. using Unity.VisualScripting;
    2. public class QuickTestUnit : Unit
    3.     {
    4.         [SerializeAs(nameof(toggle))]
    5.         bool toggle;
    6.  
    7.         [DoNotSerialize]
    8.         [Inspectable, UnitHeaderInspectable]
    9.         public bool Toggle { get => toggle; set => toggle = value; }
    10.  
    11.         protected override void Definition()
    12.         {
    13.         }
    14.     }
    You can look at the source code of the VisualScripting custom units SwitchOnString. You need activate Registry packages (in Preferences > External Tools > Generate .csproj files for: > Registry packages) and look for class that inherit Unit.
    upload_2023-6-6_15-55-20.png
    upload_2023-6-3_21-18-34.png


    Also instead of a boolean I mostly use an enum which is much more descriptive IMO.
     
    Last edited: Jun 6, 2023