Home
  • Manual
  • Node Index
  • API
  • Changelog
Search Results for

    Show / Hide Table of Contents
    • Tutorials
      • Creating your first map generator
        • 1. Creating your first map graph
        • 2. Running a graph at runtime
        • 3. Adding more nodes
        • 4. Object placement
      • Basic map types
        • • Cave-like maps
        • • Room-based maps
        • • Sample-based maps
        • • Combining map types
      • More Tutorials
        • • Generating prefabs
        • • Tile/prefab/tilemap set weights
        • • Syncing named color sets
        • • Groups
        • • Notes & comments
        • • Sub graphs
        • • Tilemap Sets
        • • Optimization tips
        • • Static seed (daily challenges)
        • • Running a graph asynchronously or multi-threaded
        • • Object pooling
        • • Tips for rule tiles
        • • Saving and loading maps
      • Tutorials for coders
        • • Running graphs from scripts
        • • Output parameters
        • • Custom nodes
        • • Custom node views
        • • Adding a constant node type
        • • Custom styling for the graph editor
        • • Dependencies for custom nodes
    • Sample Project
    • Troubleshooting
    • Support

    Running graphs from scripts

    Running a graph from a script is easy. All you need is a reference to the ScriptGraphRunner component and run it. Here's a simple example:

    using InsaneScatterbrain.ScriptGraph;
    using UnityEngine;
    
    public class RunningGraphFromScriptExample : MonoBehaviour
    {
        [SerializeField] private ScriptGraphRunner graphRunner;
    
        public void Start()
        {
            // Runs the graph. (Asynchronously, if that option has been enabled.)
            graphRunner.Run();
    
            // Runs the graph, synchronously, regardless of whether the asychronous option has ben enabled or not.
            graphRunner.RunSync();
            
            // Runs the graph, asynchronously, regardless of whether the asychronous option has ben enabled or not.
            graphRunner.RunAsync();
        }
    }
    

    Running a graph with the default runner

    You might want to run a graph without using the ScriptGraphRunner. Instead, you can run a graph using the processor directly. For example, like so:

    var processor = new ScriptGraphProcessor();
    var output = processor.Process(graph);
    

    This is not the recommended way of running graphs, because you lose all the features that come with the runner component, but if you need to run a graph without the runner component it's possible.

    In This Article
    Back to top Generated by DocFX