playtest-unity/playtest/Library/PackageCache/com.unity.visualscripting@1.../Documentation~/vs-create-custom-node-empty.md

1.9 KiB

Create a new simple Custom C# node

You can create a Custom C# node to run your own custom logic in a Script Graph. For more information on Custom C# nodes, see Custom C# nodes.

To create a new simple Custom C# node:

  1. [!includeopen-project-window]

  2. Right-click a folder in the Project window's folder list, or anywhere in the Project window's preview pane, and go to Create > C# Script.

  3. Enter a name, such as MyNode, for the new script file.

  4. Press Enter.

  5. [!includeopen-new-external-code]

  6. In your external editor, copy and paste the following code into your C# script:

    using Unity.VisualScripting;
    using UnityEngine;
    
    public class MyNode : Unit
    {
       protected override void Definition() //The method to set what our node will be doing.
       {
       }
    }
    
  7. [!includesave-script]

  8. [!includereturn-unity]

  9. [!includeregen-node-library]

    [!NOTE] If you don't regenerate your Node Library, the node won't appear in Visual Scripting's fuzzy finder.

  10. Open a Script Graph where you want to add your new node.

  11. [!includeopen-fuzzy-finder]

  12. The node appears as My Node at the end of the fuzzy finder list. Select the node to add it to your graph.

    An image of the Graph window. The fuzzy finder is open and displays the Custom C# node, My Node, at the end of the list of all available nodes. The node has also been added to the Script Graph, but has no ports.

Next steps

After you create the basic start to a node and add it to Visual Scripting's fuzzy finder, add ports so your node can send and receive data.