Unit System
  • WELCOME
    • πŸ‘‹Hello
    • πŸ—ΊοΈRoadmap
    • ⛑️Support & Community
    • πŸŽ“Version - Changelog
  • Getting Started
    • πŸ”ŒImport Package
    • βš™οΈConfiguration
    • πŸ” Database
    • πŸͺŸManager Window
    • Creating a new Scene
      • Player Camera
      • Set up Player
      • Set up Player UI
      • Set up the Game World
    • Create Units
      • Resource (Crystal)
      • Research (Crystal age)
      • Resource node (Crystal Node)
      • Resource collector (Crystal)
      • Combat unit (Mage)
      • Production unit (Mage Tower)
      • Faction (Purple Cubes)
  • How it works
    • Overview
    • Modules
      • Resource
      • Production
      • Population
      • Garrison
      • Collection
  • Integration
    • Unit Selection
    • Unit Formation
    • Object Placement
Powered by GitBook
On this page
  • Key Features
  • Structure
  • Usage Examples
  1. How it works
  2. Modules

Population

Key Features

  • Manages Player Population: Tracks and updates unit population and limits it with population capacity. This is done through Player events to ensure any changes to its units or other producible (like research) will be applied to the population module as well.

  • Population Consumption & Capacity: Uses attributes on units to determine how much population they consume or provide. Unlike most other modules that use capabilities.

  • Dynamic Population Limits: Supports increasing max population via buildings, upgrades (research), or faction settings.

  • Hard Cap for Population: Ensures population cannot exceed a predefined limit regardless of capacity provided by units in game.

  • Event-Driven Updates: Triggers population change events for UI or gameplay reactions.

  • Seamless Integration: Works alongside production module to enforce unit limits.


Structure

  • Population Module – Core module handling population tracking, limits, and consumption.

  • PopulationConsumptionAttribute – Determines how much population a unit consumes.

  • PopulationCapacityAttribute – Determines how much population a unit provides.

  • OnPopulationUpdate – Unity event that triggers whenever population changes.


Usage Examples

Checking Current Population

PopulationModule module = player.GetModule<PopulationModule>();
Debug.Log($"Current Population: {module.CurrentPopulation}/{module.MaxPopulation}");

Adding a Unit (Population Consumption)

This is manually managed by the module when listening to player's entity, unit and producible events. However, you can still manually modify population.

if (module.HasPopulationCapacity(5)
{
    module.AddPopulation(5);
}
else
{
    Debug.Log("Not enough population capacity!");
}

Increasing Max Population (e.g., Building Construction)

popModule.IncreaseMaxPopulation(10);
Debug.Log($"New Max Population: {popModule.MaxPopulation}");

Applying a Hard Cap

popModule.SetPopulationHardCap(200);
Debug.Log("Population is now capped at 200.");
PreviousProductionNextGarrison

Last updated 1 month ago