User Tools

Site Tools


Unity Mini Tutorial: Switching Scenes


Switching scenes is a common method to load a new level in a game or go to a different activity area. In order to do this properly with Unity and GestureWorks together, gestures need to be unloaded and reset to avoid problems. This tutorial discusses the proper way to switch scenes using GestureWorks Unity.

For this tutorial you will need the Core multitouch framework; a free trial is available.

Download the code for all of the C# & Unity multitouch tutorials here: gestureworks-unity on GitHub.


Estimated time to complete: 10 minutes

This tutorial assumes a basic understanding of GestureWorks setup in Unity as described in the HelloMultitouch tutorials and the Interactive Bitmap tutorial. The project MiniTutorial_ChangingScenes is also required.

Process Overview

Process Detail

1. Example of changing scenes

Copy your GestureWorks dlls to the Assets/GestureWorks/Core directory of MiniTutorial_ChangingScenes (more discussion of the process is in a previous tutorial.)

The project contains two scene files, MyScene.unity and MySceneB.unity. Open MyScene.unity and built and run. There will be two sprites with a button displayed:

Tapping the button will switch scenes. This is shown by the bitmap objects being tinted red in the other scene:

The button code that switches the scene is in Scripts/SwitchScenes.cs and is as follows:

Switching Screens SwitchScenes.cs

using UnityEngine;
using System.Collections;
using GestureWorksCoreNET;
using GestureWorksCoreNET.Unity;

public class SwitchScenes : TouchObject {
    public GestureWorksScript gestureWorks;
    private bool switchedScenes = false;
    public void Tap(GestureEvent gEvent)
    private void Switch()
        if(switchedScenes || gestureWorks == null)
        switchedScenes = true;

The object responds to touch or drag objects by calling the Switch method. The button object contains a reference to the scene’s GestureWorks GameObject and calls the SwitchScenes method on it to change scenes. This is different than the standard Unity way of switching scene files by calling:

Standard Unity way of switching scene files


2. Discussion of changing scenes

Changing scenes with GestureWorks should always be done through the SwitchScene methods in the GestureWorks GameObject. The process for switching scenes involves many steps of waiting for existing gestures to process and clearing out gestures and touch events. Calling SwitchScene handles all of these steps, not calling it and using Unity’s Application.LoadLevel directly may cause a crash (and maybe not on every game run but occasionally.) If more fine control of switching scenes is required the Coroutine UnloadScene, which SwitchScenes calls, in the GestureWorksScript can be used directly.

Continuing Education

It is the intention of this and the other GestureWorks Core tutorials to get the programmer started using the GestureWorks core framework, and is by no means an exhaustive explanation of all of the features of Gestureworks Core; in fact, we’ve only barely scratched the surface!

Additional tutorials for learning more about GestureWorks Unity:

There is also FAQ here:

For more information on GestureWorks Core, GestureML, and CreativeML, please visit the following sites:

tutorials/net_unity/unity_mini_tutorial_switching_scenes.txt · Last modified: 2015/09/10 13:27 by glass