Skip to main content

Sub-Graphs

Sub-Graphs allow you to bundle complex node logic into a single, reusable node. They are essential for maintaining large graphs and creating modular generation "functions" that can be shared across multiple projects.

Anatomy of a Sub-Graph

A sub-graph is a standard Dungeon Flow asset that contains two special nodes to define its interface:

  1. Sub Graph Input: Defines the input ports that will appear on the sub-graph node in the parent graph.
  2. Sub Graph Output: Defines the output ports that will return data to the parent graph.

Workflow: Creating a Sub-Graph

  1. Create a New Graph: Create a new DungeonFlow asset in your project.
  2. Add Interface Nodes:
    • Add a Sub Graph Input node. Use the node's inspector to add ports (e.g., a "Seed" float or a "Base Mask" bool mask).
    • Add a Sub Graph Output node. Add ports for the final results.
  3. Implement Logic: Connect nodes between the Input and Output nodes to define your processing logic.
  4. Save the Graph: Ensure the asset is saved.

Workflow: Using in a Parent Graph

  1. Add Sub Graph Node: In your main graph, right-click and search for Sub Graph.
  2. Assign Asset: In the inspector for the Sub Graph node, assign the DungeonFlow asset you created in the previous step.
  3. Connect Ports: The Sub Graph node will dynamically update its ports to match your Input/Output definitions. Connect them as you would any other node.

Best Practices

  • Encapsulation: Use sub-graphs for repetitive tasks like "Biome Blending," "Cave Post-Processing," or "Custom Noise Stacks."
  • Nesting: Sub-graphs can contain other sub-graphs, but be careful not to create circular dependencies (Graph A containing Graph B which contains Graph A).
  • Naming: Give your Input and Output ports clear, descriptive names as these will be the only things visible in the parent graph.