Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

GraphChanges

class in Unity.GraphToolkit.Editor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The set of changes to a graph reported to Graph.OnGraphChanged in a single change event.

Access this through GraphLogger.GraphChanges inside Graph.OnGraphChanged. Inspect GraphChanges.ChangedNodes, GraphChanges.ChangedVariables, GraphChanges.ChangedConstantNodes, and GraphChanges.ChangedSubgraphNodes to react to what was added or modified. Each entry's ChangeKinds property is a set of ChangeKind bit-flags describing the categories of change that apply. Removed elements are not reported, except for removed ports, which appear in ChangedNode.ChangedPorts on their owning node.

 public override void OnGraphChanged(GraphLogger graphLogger)
 {
     GraphChanges changes = graphLogger.GraphChanges;

foreach (ChangedNode changedNode in changes.ChangedNodes) { if ((changedNode.ChangeKinds & ChangeKind.Added) != 0) Debug.Log($"Node added: {changedNode.Node}");

if ((changedNode.ChangeKinds & ChangeKind.Data) != 0) Debug.Log($"Node data changed: {changedNode.Node}");

if ((changedNode.ChangeKinds & ChangeKind.Layout) != 0) Debug.Log($"Node moved or resized: {changedNode.Node}");

// Node is either a user-defined Node subclass or an IVariableNode. switch (changedNode.Node) { case IVariableNode variableNode: /* variable reference */ break; case Node userNode: /* user-defined node */ break; }

// When ChangeKind.PortChanged is set, inspect ChangedPorts for details. foreach (ChangedPort changedPort in changedNode.ChangedPorts) { if ((changedPort.ChangeKinds & ChangeKind.Removed) != 0) Debug.Log($" Port removed: {changedPort.ID}"); else Debug.Log($" Port changed: {changedPort.Port?.Name} ({changedPort.ChangeKinds})"); } }

foreach (ChangedVariable changedVariable in changes.ChangedVariables) Debug.Log($"Variable changed: {changedVariable.Variable.Name} ({changedVariable.ChangeKinds})");

foreach (ChangedConstantNode changedConstant in changes.ChangedConstantNodes) Debug.Log($"Constant node changed: {changedConstant.ConstantNode} ({changedConstant.ChangeKinds})");

foreach (ChangedSubgraphNode changedSubgraph in changes.ChangedSubgraphNodes) Debug.Log($"Subgraph node changed: {changedSubgraph.SubgraphNode} ({changedSubgraph.ChangeKinds})"); }

Properties

Property Description
ChangedConstantNodes The constant nodes that were added or modified in this change event.
ChangedNodes The nodes that were added or modified in this change event.
ChangedSubgraphNodes The subgraph nodes that were added or modified in this change event.
ChangedVariables The variables that were added or modified in this change event.