liveBook · Manning

Chapter 5: Game board and game loop

What you will learn in chapter 5 of High Performance Unity Game Development

The introduction positions Board and Game as the remaining parts of the DOD architecture and explains why Unity is the setting for implementing them.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction positions Board and Game as the remaining parts of the DOD architecture and explains why Unity is the setting for implementing them.

Key terms: Balance, GameData, Logic, Board, Game, DOD architecture

5.1 DOD architecture, continued

Introduces the roles of Game and Board in the DOD architecture and explains that their ownership pattern applies across different games.

Key terms: Board, core gameplay, MonoBehaviour, Game, Balance, GameData, menu state, gameplay loop, custom singleton MonoBehaviour, ownership pattern

5.1.1 Game

This section explains why one Game object drives the Unity game loop, how it coordinates menus and the Board, and why gameplay Logic remains independent of that Unity-facing code.

Key terms: Game, game loop, Tick(), Awake/Start/Update, Balance, GameData, MenuState, Logic, Board, singleton

5.1.2 Board

The section explains why Game controls Board’s initialization and per-frame updates while Board remains a MonoBehaviour for editor-assigned assets.

Key terms: Game, Board, Init(), Tick(), Awake/Start, Update(), MonoBehaviour, Unity editor, assets

5.1.3 Scene hierarchy

This section identifies the small set of objects in the game’s Unity scene and explains how assets are assigned for this simple implementation.

Key terms: Main Camera, Board, Game, scene hierarchy, Canvas - Main Menu, Canvas - GameOver, Canvas - In Game, assets, public variables, Unity editor

5.1.4 Unity scenes and code complexity

The section explains why this data-oriented game uses one Unity scene and represents changes to levels, menus, and enemies as changes to data rather than scene switches.

Key terms: Unity scene, level data, menu state, game loop, scene system, game state, single Unity scene, Game, GameData, Balance

5.2 The Board implementation

This section introduces the Board’s gameplay responsibilities, its Unity references, and the custom functions that manage its lifetime and per-frame work.

Key terms: Board, object pools, input, public variables, Unity editor, EnemyPrefab, UI, resource management system, Init(), Show()

5.2.1 Init()

Explains how Board.Init() prepares board resources once for the game’s lifetime while keeping the board hidden until gameplay begins.

Key terms: Init(), Show(), GameObject pool, balance, game data, Player, UI, active false, sprites, Unity Editor

5.2.2 Show()

Show() prepares gameplay data and makes the game board visible when core gameplay starts.

Key terms: Show(), Logic.StartGame(), game data, balance, main camera, GameObject pool objects, in-game UI, virtual joystick

5.2.3 5.2.3 Hide()

This section explains when the Board’s Hide() function runs and what it hides in the simple game example.

Key terms: Hide(), in-game UI, GameObject active state, object pools

5.2.4 Tick()

This section explains what the Board’s per-frame Tick() does and why its game-over handling favors a straightforward flow over a conditional wrapper or early return.

Key terms: Tick(), game data, balance, static logic Tick(), game over, if statement, early returns

5.2.5 handleInput()

This section explains how Board.handleInput() turns mouse input into player direction and virtual joystick updates while keeping branching and frame-time costs visible.

Key terms: Board, m_mouseDownPos, virtual joystick, gameData, Logic.MouseMove(), Logic.MouseUp(), member variables, Unity’s Input system, branch, Board.HandleInput()

5.3 The Game loop implementation

This section introduces Game as the central game-loop object, identifies the references and data it holds, and explains why it alone follows Unity’s MonoBehaviour lifecycle.

Key terms: Game, game loop, MonoBehaviour, singleton, Awake(), Start(), Board, MainCamera, UIMainMenu, UIGameOver

5.3.1 Start()

Start() prepares the game’s data and UI at the game-loop entry point, before core gameplay begins.

Key terms: Start(), Game, game data, board pools, main menu, StartGame()

5.3.2 StartGame()

StartGame() prepares core gameplay by hiding non-gameplay menus, showing the Board, and connecting the main menu’s Start button to that setup.

Key terms: StartGame(), Board.Show(), main camera, screen coordinates, world coordinates, Start button, Unity editor

5.3.3 Update()

This section explains how Update() drives each frame of gameplay and how changes to GameData become visible on the board.

Key terms: Update(), Start(), IN_GAME, Board.Tick(), Time, GameOver(), static Logic functions, GameData, data out, deterministic

5.3.4 GameOver()

This section explains how GameOver() switches the visible screen to the game-over menu and distinguishes hiding the board from deallocating its data.

Key terms: GameOver(), board sprites, in-game UI, game-over UI, active state, deallocate, level-specific data, garbage collector

5.4 Conclusion

The section recaps the linear DOD gameplay architecture, contrasts it with tangled OOP interactions, and explains how Board and Game divide responsibilities in Unity.

Key terms: Game, Board, Logic, Balance, GameData, DOD, OOP, OnTrigger, MonoBehaviour, singleton

5.5 Summary

This section summarizes how the Board, Game, and a single Unity scene divide responsibilities in the game architecture.

Where this is used later

Concepts explained in this chapter

← Chapter 4: Data and logic Chapter 6: Common data structures: List, Stack, and Queue →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.