liveBook · Manning

Pure function

As explained in High Performance Unity Game Development

A function whose result depends only on its inputs and that produces no externally observable side effects.

A pure function takes game data in, transforms it, and produces output using only its inputs. It avoids external dependencies such as a Game singleton, so identical inputs produce identical results. section 5.1.1

For game logic:

  • Pass required data in explicitly, such as Balance and GameData; keep logic functions independent of the singleton and Board. section 5.1.1 section 5.4
  • For pseudo-random behavior, pass a seed so the function returns the same result for the same input. section 5.1.1

Test game logic

Create GameData and Balance directly, call a static logic function, and verify the changes without setting up a Unity scene or Game singleton. section 5.1.1

Figure 5.13 The core gameplay architecture. Game takes in Balance and calls Board. Board takes in Input and calls Logic. Logic runs on arrays of data from GameData, which Board and Game then use to show the player what happened.

The diagram shows Logic between Board input and the game data it transforms. section 5.4

How High Performance Unity Game Development covers it

How deep it goes
Defines input-only dependencies and deterministic results, including seeded pseudo-randomness, without detailing implementation code.
Examples
Tests static functions with directly created GameData and Balance, and uses a seed for repeatable pseudo-random results.
What you can do after
Apply static logic functions to game data and verify results without a Unity scene or Game singleton.
How it connects
Connects Logic with GameData, Balance, Board, and the Game singleton.

Also explained in

Compare how 23 books explain pure function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.