Skip to content

Global vs Content Entities

This article explains the difference between global and content entities and how they are loaded during startup. For startup specifics see Startup Process.

Global Entities

Global Entities are entities that are globally accessible from all Contents, such as Event Settings. Global entities are marked as global using the global Beamable data tag.

Note

Users should be careful about what is put in global data since it will always be loaded into memory. Hence, data should only be global when necessary to avoid memory issues.

Content Specific Entities

Content specific Entities are entities that are only accessible from a specific content. This accounts for a majority of entities in IdleKit, such as IContent, IStage, and IGeneratorEntity. Content-specific data is marked using Beamable data tag. For example Main Game Content is tagged using mg_content.

Note

Data is differentiated by tags in Beamable but when referencing data at runtime we use its ID.

Loading & Unloading Flow

Global Entities Flow

globalentitiesflow

Content Entities Flow

contententitiesflow

Loading Global Entities

Loading of global entities must be handled by services that are in charge of loading independent entities, including: * IEventService - Loads all Event Settings * ICurrencyService - Loads all Currencies * IRewardService - Loads all Rewards * IModifierService - Loads all Modifier Formulas * ITrackService - Loads all Global Tracks and Timed Tracks

These services subscribe to the StaticDataAddedAction and StaticDataRemovedAction that is fired by the IDataService. Whenever entity data of an assignable type is added/removed, the services load/unload the entities, regardless of whether the data is global or content-specific. Since global data is loaded on StartGame and only unloaded on ResetGame(System.Boolean), global entities persist when switching content. When switching content, content data is unloaded, so services unload the content specific entities.

e.g. Currency Service loading Currencies

protected virtual void OnStaticDataAdded(StaticDataAddedAction staticDataAddedAction)
{
    foreach (Type type in staticDataAddedAction.dataIdDict.Keys)
    {
        if (typeof(ICurrencyData).IsAssignableFrom(type))
        {
            _entityLoaderService.LoadEntities<ICurrency, ICurrencyData>(staticDataAddedAction.dataIdDict[type].ToArray());
        }
    }
}

protected virtual void OnStaticDataRemoved(StaticDataRemovedAction staticDataRemovedAction)
{
    foreach (Type type in staticDataRemovedAction.dataIdDict.Keys)
    {
        if (typeof(ICurrencyData).IsAssignableFrom(type))
        {
            ICurrency[] currencies = _entityResolver.ResolveAll<ICurrency>(staticDataRemovedAction.dataIdDict[type].ToArray());
            _entityLoaderService.UnloadEntities(currencies);
        }
    }
}

Note

If you wish to load another type of entity globally, a service must be made to load and unload these entities when StaticDataAddedAction and StaticDataRemovedAction are fired.