githubEdit

SubSystems Locator

Class used to get game subsystems, using generics and then making cache of said subsystems.

The SubSystems class is used to easily find any subsystem that has been registered on it.

It helps us avoid falling into the Singleton patternarrow-up-right, and does something similar to the Service Locator patternarrow-up-right. Also good for performance reasons, It can handle over a million calls every frame with no issues.

Using the SubSystems class

To register a new subsystem you can call the SubSystems.Register(this) method, passing in a class that extends from SubSystem or NetworkSubSystem, it'll add that subsystem into a dictionary of subsystems, preventing two of the same subsystem from existing.

Then you can get this subsystem from somewhere else using SubSystems.Get<T>()

⚠️** **IMPORTANT!

Note that is done automatically by classes inheriting SubSystem and NetworkedSubSystem. They both register on Awake and unregister on Destroy:

public class SubSystem : Actor
    {
        protected override void OnAwake()
        {
            base.OnAwake();
            SubSystemLocator.Register(this);
        }

        protected override void OnDestroyed()
        {
            base.OnDestroyed();
            SubSystemLocator.Unregister(this);
        }
    }

Examples

chevron-rightGetting the spawned players listhashtag

EntitySpawnSubSystem entitySpawnSubSystem = SubSystems.Get<EntitySpawnSubSystem>();

List<PlayerControllable> playersToAssign = entitySpawnSubSystem.SpawnedPlayers;

chevron-rightEnding the round after detonating a nukehashtag

// Ends the round, regardless of how many objectives were completed SubSystems.Get<GamemodeSubSystem>().EndRound();

Last updated

Was this helpful?