Skip to content

Scene structure of locations

Ciro Continisio edited this page Jul 29, 2021 · 8 revisions

We have recurring elements in all location scenes, divided into categories by empty separator GameObjects.

[TODO: ADD HIERARCHY PIC]

Table of Contents

Manager prefabs

In this category we have some prefabs that act as global managers, who are generally necessary to play the game, and only exist in one copy. Many of these managers are waiting for an event (see Event System) called OnSceneReady to start. This event is fired by the SceneLoader script present in the scene PersistentManagers, once a location is fully loaded.

Editor initialiser
A "hack" script that takes care of initialising the scene and the game when pressing Play from the editor (something that we call "cold startup"), as if the player came through the main menu in a normal gameplay flow. This script is totally useless in the build, and in fact it is stripped from it thanks to being tagged as EditorOnly.

Spawn system
Takes care of spawning the player when the event OnSceneReady is fired. It uses the last path taken in the PathStorageSO Scriptable Object to determine in which of the many location entrances to spawn the player Prefab (see Scene entrance and exit below).

The Spawn system Prefab has a child object which represents the default location to spawn from. This location is selected if the developer presses Play in the editor, if a location is loaded from the main menu, or if for any reason the PathStorageSO data is missing. When testing often, you can reposition this object to save yourself some time so whenever entering Play mode the player is spawn exactly where you want.

Camera system
Contains the Camera GameObject, and also the Cinemachine FreeLook Virtual Camera (VCam) that acts as the main gameplay VCam. Since this VCam needs to frame the player Prefab but this is not instantiated at the beginning of the game, the Camera System script listens to an event called PlayerInstantiated which notifies it and also carries information on the Transform to frame.

It also acts as a proxy to propagate shake events to the child object ImpulseSource, receiving the notification on the CameraShake event channel coming mainly from combat actions in the State machine of the characters receiving damage.

Music player
Fires an event on an AudioCueEventChannel to notify the AudioManager script (located in the PersistentManagers scene, which is loaded at the same time at runtime) to play the music associated to the current location.

Lighting

The lighting section contains the main directional light (a Prefab that changes according to the time of the day in each scene), the light probes, and in some special cases other lights (like for the Cave location).

For light probes, the Light Probe group you find here contains just the unique light probes belonging to each location. However, many more light probes are embedded into Prefabs and merged with the unique ones. Find more details on the Lighting and GI page.

Other lights might be present in the scene, such as for instance the ones coming from torches or cooking pots. Find them all using the Light Explorer window.

Gameplay logic

This group contains all objects that are somehow "interactive" for the player. Among them, a Prefab called Interactables_[location], which includes all NPCs, enemies, cooking pots, and other interactive elements.

Cutscenes might also be present here (not in all locations) and they are usually "self-sufficient", meaning that all of the objects referenced by the Timeline are included in the Prefab.

Entrances and exits

A location can have multiple entrances and exits and they are supposed to be connecting physical locations, so we have setup a mechanism to determine - once a new scene is loaded - where the player should be entering it from. This relies on a Scriptable Object of type PathStorageSO, referenced by multiple scripts in the game. This unique Scriptable Object contains a reference to a PathSO Scriptable Object, which identifies a virtual path connecting two locations. Paths have no direction, that's why they are used for both locations connected. If locations in the island can be imagined as nodes on a network, think of paths as virtual nodes that have no physical representation but connect two location nodes.

Location exit
These GameObjects have a trigger collider to detect the player which, OnTriggerEnter, fires an event on the LoadLocation event channel to notify the SceneLoader to load a new scene. At the same time, the exit writes into the PathStorageSO which PathSO to consider the last taken path.

Location entrance
When the scene is loaded, the Spawn system finds all entrance objects in the scene and puts them in a list. When the player needs to be spawned, the Spawn system checks which entrance script references the same PathSO that is referenced in the PathStorageSO (ideally set by the previous location's exit). This means that the player took an exit in the previous scene that was supposed to take to this entrance, and so it spawns the player there.

Home
Video materials

Basics

World building and Graphics

Game architecture

The game systems explained, with API examples. For programmers.

Game design

How-tos for designers to expand the game's gameplay.

  • Adding quests
  • Adding items
  • Creating dialogues
  • Making a cutscene
Clone this wiki locally