4. Level Change

In this part, we'll add level switching when we reach the red flag at the end of a level.

1. Create the flow machine

  1. Select the Objective object in the scene view. 
  2. Add a flow machine component
  3. Convert its source to a macro called Objective
  4. Apply the changes to the prefab
  5. Delete the default Start and Update units

2. Detect player collision

The first thing we need to do is detect when the player reaches the red flag. All that's needed for this is a collision check, like we just did for spikes:

But hey, that's copy-pasting! We'll try to avoid that to keep our graphs DRY. We'll create a new super unit that handles checking for collision with an object of a given tag, and telling us whether we hit or target or another object.

Cut and paste these units in a new macro called OnCollisionWith, and add Input and Output units, both found under Nesting.

On the input node, add a string value input for the tag to check:

Make sure you check the Has Default Value option, allowing us to use inline values in the super unit. 

On the output node, add three outputs:

  • A control output in case we hit our target
  • A control output in case we hit another object
  • A game object value output for the object that we hit

Then, connect the ports on the input and output units to their matching ports in our collision check graph, like so:

Going back to our Objective graph, we can now simply drag & drop our new macro to create a super unit, then fill in the Tag field with Player:

If you want, you can also replace our previous collision detection on the Spikes graph with the new super unit. Look how simple it becomes then!

Keeping your graphs DRY might seem like overkill at first, especially for simple logic like this. But it's important to remember that as your game scales, you'll need to do this to keep everything easily maintainable. 

We're currently working on making this a one-click operation: select the units you want, then click a button to turn them into a super unit and save it as a macro. Stay tuned for updates!

2. Load the next level

Now that we have a solid, reusable collision detection, we just need to load the next scene. But because we'll be using that same Objective prefab across all our levels, we need a variable to configure which scene is the next. Add a new string object variable called Scene, and give it a value of Level2:

Then, apply the changes to the objective prefab so that they all have a Scene variable.

Later, in other levels, you'll need to change that variable to the name of the next scene. For example, in Level2, you'll select the Objective object, and change its Scene variable to Level3.

Finally, to load the level, simply connect the collision super unit with a Load Scene unit:

3. Unlock the next level for later

Later in this tutorial, when we create the main menu, we'll want only the levels that the player has entered at least once to be available for replay, so that they can't skip to the last level before having beat the previous ones.

To do that, we'll be using saved variables. This is a powerful feature of Bolt that acts as a built-in save system: any content you place in a saved variable will be persistent across playthroughs, even if you exit the game.

The convention we will be using is to have one saved variable per unlocked level. It will be a boolean (true or false) indicating whether the level is unlocked, and its name will be LevelX_Unlocked, where X changes for every level.

When the player reaches this objective, the next level should get unlocked. In order to do that, add the following nodes to your Objective graph:

Concat is located under Codebase > System > String. It takes the arguments you pass to it and joins them together. For example, here, the output of the concat unit will be Level2_Unlocked, which we use as the name of the saved variable.

Finally, tie up everything together in the graph with groups. 

If you test your game now, you should switch to level 2 once the player reaches the red flag:

You should also see a new Level2_Unlocked variable appear in the Saved tabs of the variable window:

Spikes & Death Head-Up Display (HUD)

This article was helpful for 18 people. Is this article helpful for you?


minor glitch for me

I had to change the New string object variable ‘Name’ to ‘Scenes’ Also the two 

‘Object Get Variable’ to ‘Scenes’ to get this to work  

This may save someone else time if they have the same problem

Hi, I don't know how it is for others, but is it normal that I will stand on the Flag? I know because of the collider. Wouldn't it be better to turn the collider into a trigger?

In my opinion making the flag a trigger won't be much of a difference since what the code does is, the frame you touch it, it loads the next scene.

Yeah, you are right. Was before I build in the functionality ;)

Saved variable is what? XML data, Scriptable Data or PlayerPrefs?

JSON serialized into PlayerPrefs.

Switching from level 1 to level 2 does not work well.

I went from Level 1 to Level 1, which I did in the test.

I wonder what made a mistake ...

Self-solved by registering in the build setting

Ok. If I run the game again and jump to level 2 I get a error saying More than one 'Bolt.ScenceVariables' singletion in scene 'Level1'. So I take it that this is still here and it errors when it try to save again.

This is actually a bug introduced in the latest stable version of Bolt (it doesn't exist in 1.2.1), see https://support.ludiq.io/forums/5-bolt/topics/912-issues-with-scenevariables-singleton/.  The latest version in Alpha testing (available under Builds) has this fixed, but it's an alpha.  Lazlo returns from vacation starting next week (the 15th), so expect some progress on this then.

I'm getting this problem as well, and it doesn't SEEM to cause any problems, everything seems to still function as normal, so I've been cautiously ignoring it, myself. 

I went to 1.2.1 but I cannot use now as all the windows say disabled when plugin version mismatch and I cannot reopen them (see picture)



All good, sorted it. Thank you

I'd recommend removing your phone numbers and email!  :-)

May be another bug. When I get to next level and jump I get InvalidOperationException: Variable not found: 'Jump'. Bolt.VariableDeclaration.Get(System.String variable) (at c:/User/Lazlo/Projects/Ludig/.... and so on VariableDeclaration.cs:60)

I checked my Input Manager for Level2 and Jump is setup. On Version 1.2.1 due to the other bug I found in my early post.

Thank you

That sounds like a complaint that it can't find the variable "Jump" on your game object, not the input manager.  You created a Jump variable on your object in section 2.7.  Does it still look the way it should?

Yes this was a reply email that went into the portal. Can you remove it as I could not find a re-edit or remove once posted.


can you guys help me =(

its says : Graph input cannot be used outside a super unit

this is the error i got and it never switch to the next level =(

A image of how you coded it will be useful.

here ... i hope its clear image

I'm having the same problem mentioned above. "Graph input cannot be used outside a super unit."

Here's a screenshot of my Objective graph. As I understand, it should be loading the next level, but it doesn't. 
Also, it doesn't seem to save the Level2_Unlocked variable. Can anyone help? I'm happy to provide more info.


Shoutout to Satsukeshi on the Bolt Discord #help channel for the solution.

Just have to make sure that the correct macro is set in the Flow Graph component. 

That gets rid of the error and loads the next level.