playtest-unity/playtest/Library/PackageCache/com.unity.visualscripting@1.../Documentation~/vs-nesting-add-subgraph.md

3.1 KiB

Add a Subgraph to a Script Graph

A Subgraph is a Script Graph nested inside of another Script Graph. A Subgraph appears as a single node inside a parent Script Graph. For more information on the Subgraph node, see Subgraph node.

You can add a Subgraph to a Script Graph in two ways: create a new Script Graph, or add an existing Script Graph file.

Add a new Subgraph to a Script Graph

To add a new blank Subgraph to an existing Script Graph:

  1. [!include[with-graph-open-ff](./snippets/vs-with-graph-open-ff.md)]

  2. Go to Nesting.

  3. Select Subgraph to add a Subgraph node to the graph.

  4. Open the Graph Inspector.

  5. In the Graph Inspector, choose the source for the Subgraph:

    • Embed: The Subgraph only exists on the Subgraph node. You can only change the Subgraph from the node in its parent graph.

    • Graph: The Subgraph exists in a separate file. You can change the Subgraph outside of its parent graph and reuse the graph in other areas of an application.

  6. If you chose Graph:

    1. In the Graph Inspector, select New.

    2. Enter a name for the graph file.

    3. Choose where you want to save the graph file in the project.

    4. Select Save.

An image of the Graph window, that displays a new blank Subgraph node added to a Script Graph

Add an existing Script Graph as a Subgraph

To add an existing graph file as a Subgraph in a Script Graph:

[!NOTE] You can't nest a Script Graph as a Subgraph in its own graph file.

  1. [!includewith-graph-open-ff]

  2. Go to Nesting.

  3. Select Subgraph to add the Subgraph node to the graph.

  4. Open the Graph Inspector.

  5. In the Graph Inspector, set the Source to Graph.

  6. Do one of the following:

    • In the Graph field, select the object picker (circle icon) and choose a compatible Script Graph from the project.
    • Click and drag a Script Graph file from the Project window and release on the Graph field.

An image of the Graph window, that displays a new Subgraph node created from an existing Script Graph added to another Script Graph file.

[!TIP] For a faster way to add a Script Graph as a Subgraph:

  • Click and drag a Script Graph asset from the Project window into the Graph Editor to automatically create a Subgraph node.
  • Right-click to open the fuzzy finder. Go to Graphs and select a graph file.

Next steps

To open the new Subgraph and edit the graph, select Edit Graph.

After you've added a Subgraph to a Script Graph, define its ports. For more information, see Add a Trigger or Data port to a Script Graph.