liveBook · Manning

Unity

As explained in High Performance Unity Game Development

A game engine and development platform for creating and running interactive real-time experiences.

A small game can assign prefab references through the Unity editor and retrieve instantiated copies through a singleton asset manager. This keeps references private while making asset access explicit through dedicated methods. section 7.2.1

The manager supports straightforward loading during initialization:

  • Load menu UI once and keep it in memory; load the player once; initialize an enemy pool for the Board to manage. section 7.2.1
  • Use a separate getter for each prefab or UI asset, making it clear which asset a call retrieves. section 7.2.1
Listing 7.18 The AssetManager class
public class AssetManager : Singleton<AssetManager>
{
    [SerializeField] GameObject m_playerPrefab; #A
    [SerializeField] GameObject m_enemyPrefab; #A
 
    [SerializeField] GameObject m_UIInGame; #B
    [SerializeField] GameObject m_UIMainMenu; #B
    [SerializeField] GameObject m_UIGameOver; #B
 
    public GameObject GetPlayerGameObject(Transform playerParent) #C
    {
        return Instantiate(m_playerPrefab, playerParent);
    }
 
    public GameObject GetEnemyGameObject(Transform enemyParent) #C
    {
        return Instantiate(m_enemyPrefab, enemyParent);
    }
 
    public GameObject GetInGameUI() #C
    {
        return Instantiate(m_UIInGame);
    }
 
    public GameObject GetMainMenuUI() #C
    {
        return Instantiate(m_UIMainMenu);
    }
 
    public GameObject GetGameOverUI() #C
    {
        return Instantiate(m_UIGameOver);
    }
}

The AssetManager listing shows private serialized prefab references and dedicated methods that instantiate their assets. section 7.2.1

How High Performance Unity Game Development covers it

How deep it goes
Details a singleton implementation with serialized private references and dedicated getters, while limiting its scope to straightforward asset loading.
Examples
Uses player and enemy prefabs, pooled enemies, and in-game, main-menu, and game-over UI prefabs.
What you can do after
Configure prefab references in the Unity editor and retrieve instantiated assets through dedicated methods.
How it connects
Connects prefabs, singleton design, object pooling, and data-oriented design.

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.