In this article, we review two different ways to pass information (e.g. values, user selections) from one scene to another in a running experience.
All screenshots in this article come from the sample experience here. Feel free to try things out yourself.
When building experiences in Composer, you use layers to control the order of items along the z-axis, the axis moving in and out of the screen. Items higher along the z-axis will appear in front of items located farther back.
There are two types of layers: scene layers and experience layers. Scene layers are scene-specific, while experience layers are scene-independent.
Experience layers make it possible to pass information between scenes. Because experience layers are scene-independent, they are (by default) global across the entire experience and thus visible in all scenes. As a result, any value or property set in an experience layer can be accessed by scene-dependent items, no matter in which scene those scene-dependent items are contained.
Experience layers can be placed behind scenes or in front of scenes. This placement has no affect on their visibility to scene-dependent items.
All Interface Assets (IA) can be reached from anywhere within an experience. As a result, IA properties act as global variables.
A special case is the Global Variable interface asset that exists explicitly for the purpose of holding a value across scenes.
With the use of a global variable:
- in Scene 1: use triggers and actions to store the value in this global variable
- in Scene 2: bind an asset to the same global variable to extract its value
Of course, your IA could be much more functional, implementing business logic that can process information.
In the image below, the value of a Text asset comes - via binding - from a Global Variable interface asset. Click the image to enlarge.