Garrison
Key Features
Easy Garrison Access: Provides easy access to garrisons and garrisonable units.
Entrance Positioning: Defines specific entry points for units to move to before entering a garrison.
Capacity & Eligibility: Controls how many units and which unit is eligible for entering based on predefined rules.
Unit Garrisoning & Exiting: Allows units to enter, exit garrisons.
Event-Driven Updates: Triggers events when unit enters or exits garrison for easier UI updates or gameplay logic.
Seamless Integration: Works alongside unit interactions, combat, and production systems.
Structure
Garrison Module - Manages list of garrisons and garrisonable units foe easier access, along with convenience methods. This module is completely optional, everything works if its not present on player.
Garrison Unit Capability - Defines unit garrison capabilities, amount and rules for entering.
Garrisonable Unit Capability - Defines a unit which can enter a garrison on data level.
Garrison Unit - Behaviour component for managing current of garrisoned units, adding, removing and spawning them.
Garrisonable Unit - Behaviour component for managing entering and exiting states of the object.
Garrison Events - Global events invoked for use like UI updates
Garrison Spawn Point - Additionally garrison will utilise spawn point if present on the unit. This will make units exit garrison in specific position, regardless where they entered it.
Usage Examples
Garrisoning a Soldier
When a unit needs to enter a garrison.
IUnit bunker = // Get reference of bunker
IUnit soldier = // Get reference of soldier
IGarrisonUnit garrisonUnit = bunker.GarrisonUnit;
if (garrisonUnit.IsEligibleToEnter(soldier)
{
soldier.GarrisonableUnit.EnterGarrison(garrisonUnit);
}
When unit is out of range and requires movement before entering. Validations are done as part of the EnterGarrisonTask
.
soldier.GarrisonableUnit.GoEnterGarrison(bunker.GarrisonUnit);
Auto-Garrison Nearby Units
To call nearby soldiers into a bunker:
if (bunker.Owner.TryGetModule(out GarrisonModule garrisonModule))
{
garrisonModule.CallInNearbyUnits(bunker.GarrisonUnit, range: 10f, cancelActiveTasks: false);
}
Garrison automatically gathers nearby idle soldiers.
When cancel active tasks parameter is set to
true
, it will take any soldier in range, cancel their active tasks and clear the task queue before moving to garrison.
Empty a Garrison
To release all soldiers from a bunker.
bunker.GarrisonUnit.RemoveAllUnits();
All units will exit and reappear in the game world.
Preventing Ineligible Units from Entering
This can be done as part of the unit capability configuration. When no permitted types or excluded units are specified, all units can enter.

Last updated