Quantum 102 - Setting up a Scene
Overview
Quantum 102 explains how to set up a simple Quantum scene with physics objects. It introduces the concept of entities and teaches how to create entities from inside the Unity editor.
Open Game Scene
The Unity project that comes bundled with the Quantum SDK already contains files to help you get started.
Inside the Photon/QuantumDemo
folder there is a Game
and a Menu
folder each containing a likewise named scene. These scenes act as the starting point for the Quantum 100 series.
Open the Game
scene.
There are a few noteworthy GameObjects in the scene.
MapData
: The workflow for creating scenes in Quantum is pretty much identical to creating a scene for a single player game in Unity. The map data component bakes the entities, static colliders and NavMesh data in your scene so that they can be used by the deterministic Quantum engine.- The
EnitityViewUpdater
is responsible for instantiating and destroying the GameObject representations of entities (views) for entities that are created by gameplay code at runtime. - The
LocalInput
script is an example for how to pass Unity input into the deterministic Quantum engine. It will be extended later in this series. - The
QuantumStats
GameObject displays the stats window that is visible on the left side of theGame
editor window. It displays many useful stats about the active Quantum simulation.
Note: We recommend circling back to the EntityViewUpdater at a later point in time and customize it to your game's needs. For instance by adding object pooling or changing the interpolation if needed.
Add Floor and Rigidbody
To add a floor to the scene, right-click on the Hierarchy tab in Unity and choose Quantum > 3D > Static Box Collider
. Note that there is a Quantum Static Box Collider 3D
on this object. Quantum static collider components define the static collision geometry of the Quantum map.
Rename the GameObject to Floor
and change its scale to (10, 1, 10). In the Scene view you can a green Gizmo box that matches the visual mesh. This is the Quantum static collider.
Next add a Quantum > 3D > Box Entity
. Set its position to (0, 4, 0) and the rotation to (45, 0, 45).
To Add a Rigidbody component to the entity check the PhysicsBody3D
checkbox on the Enity Prototype
component.
Enter play mode. Doing so automatically bakes the static collider into the deterministic map. The cube entity falls and lands on the floor.
Note: All data in the Quantum simulation has to be deterministic. As a result of that, when working with Quantum, a lot of nondeterministic Unity data needs to be baked into a deterministic form by data baking processes. The baked data is saved into data assets (like scriptable objects) and then accessed by the simulation.
Entities in Quantum
In Quantum all gameplay is driven by entities and systems and static data assets such as static colliders. Quantum does not handle any rendering however the EntityViewUpdater instantiates a GameObject for each entity that has a EntityPrototype with a EntityView Monobehaviour on it in Unity. This view GameObject acts as the visual representation of the entity. The transform of the view GameObjects are also automatically synchronized from their respective entities by the EntityViewUpdater.
Each entity has a set of components. Components are not Unity MonoBehaviours and are added to the entity on the EntityPrototype MonoBehavoiurs's Enity Component
list or via code. Some components are added by checking the checkboxes in the Entity Prototype component such as the PhysicsBody3D
component on the cube entity.
Quantum has a state inspector to inspect the state of entity components during runtime. In the menu bar of Unity click on Window > Quantum > State Inspector
. This opens the state inspector window. Enter play mode. In the state inspector window unfold the LOCALDEBUG
entry and the Entities
entry. The cube entity is listed. Click on it to reveal all components on the entity and their current state.