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:
- Sub Graph Input: Defines the input ports that will appear on the sub-graph node in the parent graph.
- Sub Graph Output: Defines the output ports that will return data to the parent graph.
Workflow: Creating a Sub-Graph
- Create a New Graph: Create a new
DungeonFlowasset in your project. - 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.
- Implement Logic: Connect nodes between the Input and Output nodes to define your processing logic.
- Save the Graph: Ensure the asset is saved.
Workflow: Using in a Parent Graph
- Add Sub Graph Node: In your main graph, right-click and search for Sub Graph.
- Assign Asset: In the inspector for the Sub Graph node, assign the
DungeonFlowasset you created in the previous step. - 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.