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:
- In the hierarchy window, select the object with Map Graph Runner component on it.
- 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:
- Create a UI button by selecting GameObject/UI/Button.
- Select the button in the hierarchy window.
- In the inspector, look for the OnClick event on the Button component.
- Click +, assign the Map Graph Runner object to the object field.
- 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.
Next, we'll check out how we can spice our basic map generator up a bit, to make something more interesting!