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 a graph at runtime

    In the previous tutorial we've generated our first map with Map Graph. So far, we've only seen how to do this in the editor, but of course it's also possible to do this at runtime. There are a couple of ways to do this.

    Run on start

    If you simply want a random map each time the scene (or more specifically, the Map Graph Runner) is loaded:

    1. In the hierarchy window, select the object with Map Graph Runner component on it.
    2. Look for the Run On Start option in the inspector and enable it.

    That's it! Now each time the Map Graph Runner component is loaded, it will generate a random map.

    Call Run from a Unity Event

    Another, more flexible way is, to call the Run method on the Map Graph Runner component.

    We can do that using a Unity Event on a UI button for example. Here's how:

    1. Create a UI button by selecting GameObject/UI/Button.
    2. Select the button in the hierarchy window.
    3. In the inspector, look for the OnClick event on the Button component.
    4. Click +, assign the Map Graph Runner object to the object field.
    5. Select the dropdown and pick ScriptGraphRunner/Run ()

    And now you have a UI button the generates a new map whenever it's clicked at runtime.

    Call Run from a script

    It's also possible to call the Run method from a script, however it does require some basic coding skills.

    If you want to know how to do this, check out this tutorial.

    Running graphs from scripts.

    Next, we'll check out how we can spice our basic map generator up a bit, to make something more interesting!

    3. Adding more nodes

    In This Article
    Back to top Generated by DocFX