A game about forced loneliness, made by TACStudios
1# Add relations to a Custom C# node
2
3> [!NOTE]
4> To add logic to a node, you must create a Custom C# node and add ports. [!include[vs-tasks-note-end](./snippets/custom-c-nodes/vs-tasks-note-end.md)]
5
6After you [add ports](vs-create-custom-node-add-ports.md) and [add logic](vs-create-custom-node-add-logic.md) to a node, relations help Visual Scripting correctly display a Custom C# node in a Script Graph.
7
8To add relations to a node:
9
101. [!include[open-project-window](./snippets/vs-open-project-window.md)]
11
122. [!include[open-existing-external-code](./snippets/vs-open-existing-external-code.md)]
13
143. In your external editor, add relations in the format `$RelationType$($Port1$, $Port2$)`, where `$RelationType$` is the relation type you want to assign between the ports you specify as `$Port1$` or `$Port2$`.
15
16 For example, to assign relations to the previous example node:
17
18 ```C#
19 using System;
20 using Unity.VisualScripting;
21 using UnityEngine;
22
23 public class MyNode : Unit
24 {
25 [DoNotSerialize]
26 public ControlInput inputTrigger;
27
28 [DoNotSerialize]
29 public ControlOutput outputTrigger;
30
31 [DoNotSerialize]
32 public ValueInput myValueA;
33
34 [DoNotSerialize]
35 public ValueInput myValueB;
36
37 [DoNotSerialize]
38 public ValueOutput result;
39
40 private string resultValue;
41 protected override void Definition()
42 {
43 inputTrigger = ControlInput("inputTrigger", (flow) =>
44 {
45 resultValue = flow.GetValue<string>(myValueA) + flow.GetValue<string>(myValueB) + "!!!";
46 return outputTrigger;
47 });
48 outputTrigger = ControlOutput("outputTrigger");
49
50 myValueA = ValueInput<string>("myValueA", "Hello ");
51 myValueB = ValueInput<string>("myValueB", String.Empty);
52 result = ValueOutput<string>("result", (flow) => resultValue);
53
54 Requirement(myValueA, inputTrigger); //Specifies that we need the myValueA value to be set before the node can run.
55 Requirement(myValueB, inputTrigger); //Specifies that we need the myValueB value to be set before the node can run.
56 Succession(inputTrigger, outputTrigger); //Specifies that the input trigger port's input exits at the output trigger port. Not setting your succession also dims connected nodes, but the execution still completes.
57 Assignment(inputTrigger,result);//Specifies that data is written to the result string output when the inputTrigger is triggered.
58 }
59 }
60
61 ```
62
63 For more information on relation types, see [Custom C# nodes](vs-create-custom-node.md#relation-types).
64
654. [!include[save-script](./snippets/vs-save-script.md)]
66
671. [!include[return-unity](./snippets/vs-return-unity.md)]
68
695. Do one of the following:
70
71 - [!include[open-graph-w-node](./snippets/custom-c-nodes/vs-open-graph-w-node.md)].
72 - [!include[ff-add-node](./snippets/custom-c-nodes/vs-ff-add-node.md)]
73
746. In the [Graph toolbar](vs-interface-overview.md#the-graph-toolbar), enable **Relations**.
75
76 Visual Scripting displays the relations you assigned to the Custom C# node. If you used the previous code sample, the node's relations might look like the following image:
77
78 
79
80## Next steps
81
82After you add relations to a node, you can choose to [add documentation](vs-create-custom-node-add-docs.md) or [customize the node with attributes](vs-create-custom-node-attributes-reference.md).