<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" />

Navigation

</aside>

🏠 Home Page

Getting Started

Architecture

Level System

Characters & Vehicles

Run Mechanics

World Objects

Boosters & Modifiers

Progression & Economy

UI

Save & Debugging

Modules

Publishing

Reference

💰 Monetization (Ads & IAP)

<aside> 💡 The Init scene starts the game. It initializes all modules in a fixed order, then loads the Game scene.

</aside>

Boot sequence

  1. The Init scene contains the Game Loading object. GameLoading waits one frame and calls Initializer.Init().
  2. Initializer creates the consent data and calls PreInit() on every IPreInitializable component. The object is kept between scenes with DontDestroyOnLoad.
  3. GameLoading runs every ILoadingStep found on the Initializer object (for example the network check). A failed step shows an error message and waits for a retry.
  4. Initializer.InitModulesAsync() initializes the modules from Project Init Settings one by one. Each module is awaited before the next one starts.
  5. Initializer.InitSDKs() initializes the SDKs from the SDKs prefab.
  6. GameLoading loads the next scene in the Build Settings (Game). The loading screen stays for at least two seconds.

Project Init Settings

Assets/Project Files/Data/Project Init Settings.asset stores the ordered list of init modules. The order is the initialization order. A module can use only modules that are listed above it.

# Module What it creates
0 Save Controller SaveController, loads the save file, auto-save timer.
1 Pool PoolManager component on the Initializer object.
2 Tween The Tween update loops and custom easing functions.
3 Audio Controller AudioController from the Audio Registry.
4 Currencies CurrencyController from the Currency Database.
5 Haptic The Haptic system.
6 Screen Settings Target frame rate, battery save frame rate and sleep timeout.
7 Game Settings GameData.Data, the global game settings.
8 Boosters BoosterController from the Booster Database.
9 PreRunModifiers PreRunModifierController from the Pre Run Modifier Database.

Open the asset in the Inspector to add, remove or reorder modules. The Add Module menu lists the modules registered with RegisterModule. Modules registered with core: true (Save Controller, Pool, Tween, Audio Controller) are required by the framework and are not offered in that menu. A module that is already in the list is shown as disabled.

init-settings.png

How to add a new Init Module

  1. Create the module class. Inherit from InitModule and mark it with RegisterModule.

    using System.Collections;
    using UnityEngine;
    
    namespace Watermelon
    {
        [RegisterModule("My Feature", false)]
        public class MyFeatureInitModule : InitModule
        {
            public override string ModuleName => "My Feature";
    
            [SerializeField] MyFeatureDatabase database;
    
            public override IEnumerator InitAsync(GameObject owner)
            {
                // Create the controller here
                yield break;
            }
    
            public override void Unload()
            {
                // Release the controller here
            }
        }
    }
    
  2. Add the module to the list. Open Project Init Settings and choose Add Module → My Feature. The menu path is the first argument of RegisterModule.

  3. Order the module. Move it below every module whose controllers it uses.

  4. Assign the references. Link the database or settings asset in the module fields.

Game Settings and GameData

GameInitModule stores the Game Data asset and calls GameData.Init(), which sets the static GameData.Data. Game Data contains:

GameController logs an error when GameData.Data is empty. Add Game Settings to Project Init Settings and link the Game Data asset in that case.

Unloading

When the Initializer object is destroyed, the modules are unloaded and the init state is reset. GameController.Unload() saves the game before the unload callback runs.