-
Notifications
You must be signed in to change notification settings - Fork 2
Value Ports
public class ValuePort<T>
For Api see Value Port Api
Value Port's are the heart of any graph, they define the directional flow and the data passing between nodes. Value Ports are defined on Runtime Nodes, so you should check out those docs first. Defining a Value Port is easy,
//These options in english are: "Show Backing Value : False", "Port Capacity: Multi"
[In(false, Capacity.Multi), SerializeField]
public ValuePort<string> stringInput = new ValuePort<string>();
Simply define a port with a given type. There's a few things to note, ValuePorts must be marked with either In
or Out
to be useful. If you intend to use the backing value of the port, it must be serializable and be marked as [SerializeField]
. It's okay to use classes that are not serializable, but the backing value will not save as you work on the graph, so you'll need some way to inject the value into the graph (Like a scriptable object with a reference value, for example.)
ValuePorts are home to the connections aka Links of the graph. If you aren't sure what a link is, now is a good time to check out the link docs. To access links, you simply access Links
foreach (var link in stringInput.Links)
{
//Try getting the value of our link,
if (stringInput.TryGetValue(link, out var value))
{
//Then debug it!
Debug.Log("Value of link: " + value);
}
}
As a note, if you'd like to try getting the link value as a type other than the type of your value port, you can use
public bool TryGetValueAs<SomeType>(Link link, out SomeType value)
Additionally, Value Ports have a shorthand for accesing the first link, advisable for use with single connection value ports, not with multi!
public T FirstValue(); //Value of the first link
public bool TryGetFirstValue(out T value);
public RuntimeNode FirstNode(); //Node of the first link
public Link FirstLink(); //The... first link
As the comments suggest, these give the first Value, Node, or Link respectively.
Tutorials
Usage Examples
Api Documentation
- Graph
- Blackboards
- Ports
- Attributes
- Views
Advanced
In Testing