Skip to main content

Nodes

Nodes are units of logic that can be connected together to create complex behaviors. They can be thought as functions in a program but with a visual representation.

Type Definition

You can create node types that can be instantiated and stored in a blueprint. A node type inherits from the Node type and is decorated with the [NodeType] attribute, like below:

using Warudo.Core.Attributes;
using Warudo.Core.Graphs;

[NodeType(
Id = "c76b2fef-a7e7-4299-b942-e0b6dec52660",
Title = "Hello World",
Category = "CATEGORY_DEBUG",
Width = 1f
)]
public class HelloWorldNode : Node {
// Node implementation
}

Here's a summary of the parameters:

ParametersTypeData TypeDescription
IdMandatorystringThe unique identifier of this node class.
You should generate a new GUID for each new node type.
Note: the Id of the node class is different from the UUID of a node instance (node.Id).
TitleOptionalstringThe name of this node that will be displayed in the node palette.
CategoryOptionalstringThe group of this node in the node palette.
WidthOptionalfloatThe width of this node, which is by default 1f.
A node with a width of 2f will take up twice the space of a node with a width of 1f.
About Category
  • You can use the built-in Category strings listed in the Table below.
    • They will be automatically localized to the program's language.
  • You can also use your own custom Category names.
    • We strongly recommend doing this when you want to upload this node to the workshop.
    • And using the plugin name as the Category allows users to more clearly know that the node they are using is from a plugin, and which plugin is the node from.

Table The built-in Category strings and their localized text.

Categoryenzh_CNja
CATEGORY_ACCESSORIESAccessories配件付属品
CATEGORY_ANIMATIONAnimation动画アニメーション
CATEGORY_ARITHMETICArithmetic运算計算
CATEGORY_ASSETSAsset资源アセット
CATEGORY_BLENDSHAPESBlendShapesBlendShapeBlendShape
CATEGORY_CHARACTERSCharacters角色キャラクター
CATEGORY_CINEMATOGRAPHYCinematography摄影撮影
CATEGORY_CONDITIONALSConditionals条件条件
CATEGORY_CONTROL_FLOWFlow Control流控制フローコントロール
CATEGORY_DATAData数据データ
CATEGORY_DEBUGDebug调试デバッグ
CATEGORY_ENVIRONMENTSEnvironment环境環境
CATEGORY_EVENTSEvents事件イベント
CATEGORY_EXTERNAL_INTEGRATIONExternal Integration外部集成外部統合
CATEGORY_GRAPHSBlueprints蓝图ブループリント
CATEGORY_INPUTInput输入
CATEGORY_LIGHTSLights光源ライト
CATEGORY_LITERALSLiterals字面量リテラル
CATEGORY_MOTION_CAPTUREMotion Capture动作捕捉モーションキャプチャー
CATEGORY_PROPProps道具道具
CATEGORY_SCENEScene场景Scene
CATEGORY_SWITCHESSwitches切换切り替え
CATEGORY_VARIABLESVariables变量変量

Components

A node type can define data inputs, data outputs, flow inputs, flow outputs, and triggers.

Lifecycle

In addition to the lifecycle stages listed on the Entities page, nodes have the following additional lifecycle stages:

  • OnAllNodesDeserialized(): Called after all nodes in the belonging blueprint are deserialized. This is useful when you need to access other nodes in the same blueprint.
  • OnUserAddToScene(): Called when the node is just instantiated in the blueprint editor, by the user dragging it from the node palette.

Triggering Flows

You can trigger an output flow by returning the Continuation of the flow output in a flow input method. For example:

[FlowInput]
public Continuation Enter() {
// Do something
return Exit;
}

[FlowOutput]
public Continuation Exit;

If your flow ends here, you can return null to indicate that the flow has ended.

[FlowInput]
public Continuation Enter() {
// Do something
return null;
}

Sometimes, you may want to delay the flow output or trigger a flow output manually. You can use the InvokeFlow(string flowOutputPortKey) method to trigger a flow output. For example:

[FlowInput]
public Continuation Enter() {
async void TriggerExitLater() {
await UniTask.Delay(TimeSpan.FromSeconds(5));
InvokeFlow(nameof(Exit)); // Start a new flow from the "Exit" output port
}
return null; // You still need to return a Continuation. Since *this* flow technically ends here, we return null
}

Non-Serializable Data Inputs & Outputs

One thing special about nodes is that they can have non-serializable data inputs and outputs (you can't do that in assets or plugins - they will just not display at all). This allows nodes to pass, e.g., Unity objects like GameObject or Texture2D between each other and process them.

You can even have a generic data input or output, like this:

[DataInput]
public object MyGenericInput; // Note it's 'object', not 'Object'

[DataOutput
public object MyGenericOutput() => ...

Data output port of any type can be connected to MyGenericInput (the value will just be upcast to object). Conversely, MyGenericOutput can be connected to any data input port, but the value received by the input port will be null if the input port type is not compatible with the underlying type of what MyGenericOutput returns.

Type Converters

When connecting nodes, you will notice Warudo will automatically convert the data type if possible. For example, it is possible to connect a float output to an int input - the value is simply truncated.

You can register custom type converters using the DataConverters class. The easiest way is to implement the DataConverter<T1, T2> class:

public class MyFloatToIntConverter : DataConverter<float, int> {
public override int Convert(float data) => (int) data;
}

Then, register the converter in the OnCreate method of your plugin:

public override void OnCreate() {
base.OnCreate();
DataConverters.RegisterConverter(new MyFloatToIntConverter());
}
注意

You should not register type converters in your node type's OnCreate - you will register them each time a node instance is created!

Code Examples

Basic

Advanced

当前页面还没有中文翻译,帮助我们改进!

你正在阅读的页面还没有对应的中文翻译。 如果可以的话可以在 Github 提交你的翻译帮助我们改进!

上次更新于 2024.12.10