Home
  • Manual
  • Node Index
  • API
  • Changelog
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
      • • Using prefabs instead of tilemaps
      • • Changing tile/prefab/tilemap set probabilities (weighted random)
      • • Linking a named color set to tilesets/prefab sets
      • • Organizing nodes into groups
      • • Adding notes & comments
      • • Running a graph within a graph (Sub graphs)
      • • Tilemap Sets
      • • Optimization tips
      • • Static seed (daily challenges)
      • • Running a graph asynchronously/multi-threaded
      • • Object pooling
      • • Tips for rule tiles
      • • Saving and loading maps
    • Tutorials for coders
      • • Running graphs from scripts
      • • Output parameters
      • • Creating your own nodes
      • • Creating your own node views
      • • Adding a constant node type
  • 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