liveBook · Manning

Chapter 8: Separating asset data and logic

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

This introduction explains why menu development benefits from separating dynamic UI asset data from static components and treating each menu’s needs independently.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why menu development benefits from separating dynamic UI asset data from static components and treating each menu’s needs independently.

Key terms: dynamic components, static components, UI prefab, asset data, dynamic, data requirement, stand-alone, generic solution

8.1 Separating menu data from logic

The section describes the game’s existing menus and argues for implementing each menu according to its own data needs rather than designing a shared menu system in advance.

Key terms: main menu, in-game menu, game-over menu, in-game timer, Board, GameObjects, DOD, reusable menu architecture, data requirements, code reuse

8.2 The main menu implementation

The section cautions against choosing arrays by habit when designing a menu with DOD and explains when arrays can still be useful.

Key terms: data-oriented design, data, patterns, array, references, cache-line optimization

8.2.1 Understanding the asset data problem

This section identifies the main menu data that code must access and explains why separating prefab asset data from script logic would simplify the artist–engineer workflow.

Key terms: Best Time, Continue, New Game, tool time, GameData, GameObject.Find(), public variables, prefab, UI objects, asset data

8.2.2 Separating asset data from logic

The section shows how GUIRef lets artists assign stable keys to prefab UI references so engineers can retrieve them without depending on UI object names.

Key terms: GUIRef, prefab, key/value pair, key, GameObject.Find, contract, struct, array, dictionary, GetGameObject()

8.2.3 Introducing the meta data

The section separates data used outside core gameplay from GameData and introduces MetaData to hold the best time and menu state.

Key terms: core gameplay, meta, best time, GameData, menu state, meta data, enum, logic, state machine, MetaData

8.2.4 The main menu implementation

This section implements a main menu controller that stays independent of its UI prefab, caches UI references, and refreshes the menu from game and meta data when shown.

Key terms: MainMenuVisual, UI prefab, active false, Unity’s lifecycle, Init(), MainMenuGUI, GUIRef, AssetManager, listener, ContinueButton

8.3 The game over menu implementation

The section applies the main menu’s data-and-logic separation to the game-over menu, identifying where its UI data comes from and what its visual script does.

Key terms: game-over UI prefab, GUIRef, AssetManager.GetGameOverUI(), GameOverVisual

8.3.1 Init()

The section describes how Init() prepares the game-over menu by storing data and UI references and wiring its buttons.

Key terms: Init(), MetaData, GameData, GameOverGUI, asset manager singleton, GUIRef

8.3.2 Show()

Showing the game over menu uses references saved during Init() and a shared helper to format its time strings.

Key terms: Show(), Init(), MetaData, GameData, Best time, Game time

8.3.3 Hide()

8.3.4 goToMainMenu()

This subsection identifies a game-over-menu method that returns to the main menu.

Key terms: game over menu, main menu

8.4 The pause menu implementation

The pause menu uses one button to return the menu state to IN_GAME, leaving menu visibility to the state machine.

Key terms: pause menu, IN_GAME, menu state, state machine

8.5 The in-game menu implementation

This section updates the Board-controlled in-game menu to use GUIRef and the same asset-based approach as the other menus.

Key terms: BoardGUI, GUIRef, asset manager, Init(), Tick(), CommonVisual

8.6 Connecting the menus in the game loop

The game loop can control the menus if it has references to their scripts and knows which menu is current.

Key terms: game loop, menu scripts, references

8.6.1 Referencing the menus

The Game script initializes the menus, switches between them using menu state, and enters gameplay either with new data or a saved game.

Key terms: Game script, Start(), meta data, menu scripts, state machine, MetaData.MenuState, SetMenuState(), Logic.SetMenuState(), if/else, switch

8.7 Building complex menus

This section shows how to build a complex Unity store menu from nested prefabs and GUIRefs, then weighs a memory-saving approach for large inventories against its performance cost.

Key terms: nested prefabs, GUIRef, GameObject containers, Init(), Show(), Hide(), scrolling container, item prefab, asset manager, garbage collector

8.8 Conclusion

The section concludes that separating asset data streamlines collaboration, while independent menus and restrained code sharing keep menu code simpler.

Key terms: asset data, assets, development flow, menus, static function, DOD architecture, code complexity, performance

8.9 Summary

Summarizes how separating menu asset data from logic, keeping metadata distinct from gameplay data, and organizing menus independently can simplify development and debugging.

Concepts explained in this chapter

← Chapter 7: Separating data and logic Chapter 9: Tooltime data parsing →

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.