Identity Node
The Identity Node takes a single input of any type, and outputs the inputted value without changing or mutating it.
Creating Nodes
Here's a video tutorial on creating all node variants in Jungle.
Overview
This node type is useful for nodes that do not require an input to function. For instance, a node that waits for a set amount of time before continuing.
The inputted value is stored internally and cannot be modified or changed.
The input port and output port name can be defined by adding the IdentityNode
attribute to your node script.
IdentityNode
attribute properties:
Property | Type | Description |
---|---|---|
InputPortName | string | Defines the name of the input port. |
OutputPortName | string | Defines the name of the output port. |
[IdentityNode(
InputPortName = "My Input",
OutputPortName = "My Output"
)]
public class MyIdentityNode : IdentityNode
...
Result in the Jungle Editor
What makes the identity node unique is that the input port type and output port type is defined by the node connected to its input.
The WaitForSecondsNode
above is an Identity node. The GetTransformNode
and GetRigidbodyNode
are IO nodes.
Since the WaitForSecondsNode
's input port type is defined by the connected node, it can accept either type.
The IdentityNode
class inherits from the JungleNode
class.
This means all public and protected members of JungleNode
are accessible within IdentityNode
.
Read about the base JungleNode
class here.
Properties
Uid
public string Uid { get; }
Gets the unique identifier for this node.
JungleTree
public JungleTree JungleTree { get; }
Gets a reference to the original tree this node is part of.
OutputPorts
public Port[] OutputPorts { get; }
Gets the list of output ports for this node.
Nothing
public static readonly Port.None Nothing
Gets the shorthand equivalent of new Port.None()
.
IsPlayback
public bool IsPlayback { get; }
Indicates whether this node is an instance of a playback.
Playback
public JunglePlayback Playback
Gets the playback instance associated with this node.
Methods
GetInputPortInfo
public override Port.Info GetInputPortInfo()
Returns information about the node's input port.
GetOutputPortsInfo
public override Port.Info[] GetOutputPortsInfo()
Returns information about the node's output ports.
AddRevertAction
public string AddRevertAction(Action action)
Adds a revert action to be executed when the playback stops.
Call
protected void Call()
Sends out a port call without stopping the node.
Stop
protected void Stop()
Stops the node without sending out a port call.
CallAndStop
protected void CallAndStop()
Sends out a port call and stops the node.
OnStart
protected abstract void OnStart()
Invoked immediately when this node is started.
OnStop
protected virtual void OnStop()
Invoked immediately when this node is stopped.
OnUpdate
protected abstract void OnUpdate()
Invoked every frame while this node is running.
OnLateUpdate
protected virtual void OnLateUpdate()
Invoked every frame after every update function has been called.
OnFixedUpdate
protected virtual void OnFixedUpdate()
Invoked every fixed frame while this node is running.
OnValidation
protected virtual string[] OnValidation()
Called whenever the tree performs a validation pass. Should return a list of issues with the node if any.
Boilerplate
using Jungle;
[NodeProperties(
Title = "Identity Node",
Description = "One input, one output."
)]
[IdentityNode(
InputPortName = "Input",
OutputPortName = "Output"
)]
public class MyIdentityNode : IdentityNode
{
protected override void OnStart()
{
CallAndStop();
}
protected override void OnUpdate() { }
}
Example
Here's a simple example of a identity node that waits for some time before continuing.
using Jungle;
[NodeProperties(
Title = "Wait For Time",
Description = "One input, one output.",
Color = Yellow
)]
[IdentityNode(
InputPortName = "Start",
OutputPortName = "Elapsed"
)]
public class WaitForTimeNode : IdentityNode
{
[SerializeField]
private float waitTime = 1f;
private float _startTime;
protected override void OnStart()
{
_startTime = Time.time;
}
protected override void OnUpdate()
{
if (Time.time - _startTime < waitTime)
return;
CallAndStop();
}
}
As shown in the example above, the input port is named Start and accepts any type, and the output port is named Elapsed and outputs the inputted type.
With this setup, when a node calls this node, the inputted value will be stored in the WaitForTimeNode
internally and
outputted after the set amount of time has elapsed.
This configuration allows us to create a node that waits for a set amount of time before continuing.