logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityAchievementInstaller

    Unity-specific installer for the Achievements system. Loads a UnityAchievementSettings asset (soft fallback to the shared defaults when none is found), has Serenity.Achievements.Installation.Installers.AchievementCompositionRoot wire the module from it, and owns that composition's lifetime.

    Inheritance
    object
    UnityAchievementInstaller
    Implements
    IFoundationInstaller
    IInstaller
    IDisposable
    Namespace: Serenity.Achievements.Installation.Installers
    Assembly: Serenity.UnityAchievements.Installation.dll
    Syntax
    public class UnityAchievementInstaller : AchievementInstaller, IFoundationInstaller, IInstaller, IDisposable
    Remarks

    This type answers WHEN the module lives and dies — install once, discard a previous pass, tear the collaborators down in dependency order, and abandon a load that a teardown overtook. HOW the module is wired lives in Serenity.Achievements.Installation.Installers.AchievementCompositionRoot, and arrives here as one Serenity.Achievements.Installation.Installers.AchievementComposition to hold and to dispose.

    The declared achievements come from an IAchievementDefinitionSource — the Unity module's own loads every UnityAchievementDefinition asset by Addressables label. A source that also declares unlock conditions (an IAchievementConditionSource) has them read in the same pass; without one the module still installs, and every achievement waits for a code unlock instead of evaluating a tree.

    Constructors

    UnityAchievementInstaller(IEventDispatcherService, Func<IScoreService>, Func<IGameProgressService>, ITimeProvider, IAchievementDefinitionSource, IAchievementScreenshotStore, ILogService, UnityAchievementSettings)

    Initializes the Unity Achievements installer with its optional collaborators.

    Declaration
    public UnityAchievementInstaller(IEventDispatcherService eventDispatcherService, Func<IScoreService> resolveScoreService, Func<IGameProgressService> resolveGameProgressService, ITimeProvider timeProvider, IAchievementDefinitionSource definitionSource, IAchievementScreenshotStore screenshotStore, ILogService logService, UnityAchievementSettings wiredSettings = null)
    Parameters
    Type Name Description
    IEventDispatcherService eventDispatcherService

    Dispatcher used to broadcast unlock signals and to feed the evaluator. May be null.

    Func<IScoreService> resolveScoreService

    Resolves the Score service, retried until it answers. May be null.

    Func<IGameProgressService> resolveGameProgressService

    Resolves the GameProgress service, retried until it answers. May be null.

    ITimeProvider timeProvider

    Frame timings source for the evaluator's tick. May be null.

    IAchievementDefinitionSource definitionSource

    The achievements this project declares. May be null for an empty registry.

    IAchievementScreenshotStore screenshotStore

    Where unlock screenshots are kept. May be null; unlocks are then recorded without one.

    ILogService logService

    Service for logging and error reporting. May be null.

    UnityAchievementSettings wiredSettings

    The settings asset the composition root carries, or null to discover one by label.

    Methods

    Dispose()

    Tears the module down, in dependency order: the signal binder, the evaluator, the runner and capturer game objects, the platform gateway, then the service itself.

    Declaration
    public void Dispose()
    Remarks

    Destroying the runner disposes the binder through the runner's own OnDestroy. The binder is disposed here as well because a composition torn down before the runner ever awoke — an installer built and dropped in a test — has no OnDestroy to rely on, and disposing twice is explicitly safe. This runs on a domain reload, so no collaborator's failure may stop the rest: each one is disposed inside its own guard, reported and skipped, and the composition is released whatever any of them did.

    Bumps Serenity.Achievements.Installation.Installers.UnityAchievementInstaller._installGeneration first, before touching any collaborator. A load still in flight from the composition being discarded here captured the generation it was started with; once this runs, that captured value no longer matches, so the load bails out instead of writing its result into fields the next composition — or nothing at all — already owns.

    GetDefinitionSource()

    Gets the source this module's achievements were declared through.

    Declaration
    public IAchievementDefinitionSource GetDefinitionSource()
    Returns
    Type Description
    IAchievementDefinitionSource
    Remarks

    Published so the achievements views can recover what the runtime definitions cannot carry: the authored icon is a Unity Sprite, which never crosses into the engine-free registry. Asking this installer for the source it already loaded is what stops the view layer from starting a second Addressables pass over the same assets.

    GetSettings()

    Gets the loaded settings asset, or null when none was found.

    Declaration
    public UnityAchievementSettings GetSettings()
    Returns
    Type Description
    UnityAchievementSettings

    GetSettingsReadModel()

    Gets the configuration the service actually runs on: the asset, or the defaults.

    Declaration
    public IAchievementSettings GetSettingsReadModel()
    Returns
    Type Description
    IAchievementSettings

    Install(ILogService)

    Installs the Achievements system: loads the settings asset (optional), has the composition root wire the whole module from it, and hydrates it from the store in the background.

    Declaration
    public override void Install(ILogService logService)
    Parameters
    Type Name Description
    ILogService logService

    Logging service for the installation pass.

    Remarks

    Idempotent. A second call tears the previous composition down first — the pipeline can be hand-edited to carry the task twice, and two live compositions would double every signal subscription, tick every tree twice, and race two services against one store.

    Implements

    IFoundationInstaller
    IInstaller
    IDisposable
    In this article
    © 2026 Serenity. All Rights Reserved