Unity RTS Engine

  1. Home
  2. Unity RTS Engine
  3. Scripting
  4. Custom Events

Custom Events

The RTS Engine allows to customize your RTS game furthermore using custom delegate events. To make use of those events, make sure that you have the Custom Events component in the map (you can find it attached to the “GameManager” object when creating a new map using the RTS Engine menu editor).

The custom events also allow you to access components of objects that are related to the event. For example one of the events is called when a unit is created, from this event you can access the whole Unit component of the newly created unit and get/set attributes and call methods from within the Unit component.

Full list of the custom delegate events:

Entity (Unit, building or resource) Related:

  • EntitySelected (Entity entity): called when an entity is selected.
  • EntityDeselected (Entity entity): called when an entity is deselected.

Faction Entity (Unit or building) Related:

  • FactionEntityDead (FactionEntity factionEntity): called when a faction entity is destroyed.
  • FactionEntityMouseEnter (FactionEntity factionEntity): called when the player hovers with the mouse over a faction entity.
  • FactionEntityMouseExit (FactionEntity factionEntity): called when the player stops hovering with the mouse over a faction entity.

Unit Related:

  • UnitCreated (Unit unit): called when a unit is created.
  • UntiDead (Unit unit): called when a unit is dead.
  • UnitSelected (Unit unit): called when the player selects a unit.
  • UnitDeselected (Unit unit): called when the player deselects a unit.
  • UnitMoveAttempt (Unit unit): called when the player attempts to move a unit.
  • UnitWanderToggled (Unit unit): called when the unit starts/stops wandering.
  • UnitInstanceUpgraded (Unit unit): called when the unit instance is about to be upgraded (destroyed and replaced by the upgrade target).

Unit Health Related:

  • UnitHealthUpdated (Unit unit, float healthPoints, FactionEntity source): called when a unit’s health is updated by healthPoints, with source being the faction entity (unit/building) that caused this health update.

Resource Collection Related:

  • UnitStartCollecting (Unit unit, Resource resource): called when a unit starts collecting a resource.
  • UnitStopCollecting (Unit unit, Resource resource): called when a unit stops collecting a resource.
  • UnitCollectionOrder (Unit unit, Resource resource): called when the player orders a unit to collect a resource.
  • UnitDropOffStart (Unit unit, Resource resource): called when a unit starts dropping off resources.
  • UnitDropOffComplete (Unit unit, Resource resource): called when a unit completes dropping off resources.

Building Construction Related:

  • UnitStartBuilding (Unit unit, Building building): called when a unit starts constructing a building.
  • UnitStopBuilding (Unit unit, Building building): called when a unit stops constructing a building.
  • UnitBuildingOrder (Unit unit, Building building): called when the player orders a unit to construct a building.

Healer Related:

  • UnitStartHealing (Unit unit, Unit targetUnit): called when a unit starts healing a friendly unit (targetUnit).
  • UnitStopHealing (Unit unit, Unit targetUnit): called when a unit stops healing a friendly unit (targetUnit).

Converter Related:

  • UnitStartConverting (Unit unit, Unit targetUnit): called when a unit starts converting an enemy unit (targetUnit).
  • UnitStopConverting (Unit unit, Unit targetUnit): called when a unit stops converting an enemy unit (targetUnit).
  • UnitConvertionStart (Unit unit, Unit targetUnit): called when a unit is about to be converted by an enemy unit (targetUnit).
  • UnitConvertionComplete (Unit unit, Unit targetUnit): called when a unit is finally fully converted by an enemy unit (targetUnit).

Attack Related:

  • AttackSwitch (AttackEntity attackComp, FactionEntity target): called when a faction entity switches its attack component to attackComp.
  • AttackTargetLocked (AttackEntity attackComp, FactionEntity target): called when a faction entity’s attack component (attackComp) locks a faction entity to attack (target).
  • AttackPerformed (AttackEntity attackComp, FactionEntity target): called when a faction entity’s attack component (attackComp) performs an attack directed at target (for example, when it launches its attack object towards the target).
  • AttackerInRange (AttackEntity attackComp, FactionEntity target): called when the faction entity with the attackComp enters in attack range of its target.
  • AttackCooldownUpdated (AttackEntity attackComp, FactionEntity target): called when the faction entity with the attackComp is in cooldown mode regarding the attack handled by attackComp. The target here represents the attacker’s target at that time.
  • AttackDamageDealt (AttackEntity attackComp, FactionEntity target, int damage): called when the faction entity with the attackComp deals damage to its target.

Building Related:

  • BuildingPlaced (Building building): called when a building is placed.
  • BuildingBuilt (Building building): called when a building is completely constructed after being placed.
  • BuildingDestroyed (Building building): called when a building is destroyed.
  • BuildingSelected (Building building): called when the player selects a building.
  • BuildingDeselected (Building building): called when the player deselects a building.
  • BuildingStartPlacement (Building building): called when the player starts placing a building.
  • BuildingStopPlacement (Building building): called when the player stops placing a building.
  • BuildingInstanceUpgraded (Building building): called when the building instance is about to be upgraded (destroyed and replaced by the upgrade target).

Resource Generator Related:

  • Resource Generator Full (ResourceGenerator resourceGenerator, int generatorID): called when a building with the Resource Generator component has one of its resource generators (under the ID generatorID) is full.
  • Resource Generator Collected (ResourceGenerator resourceGenerator, int generatorID): called when a building with the Resource Generator component has one of its resource generators (under the ID generatorID) collected and the generated resources are added to the faction.

Building Health Related:

  • BuildingHealthUpdated (Building building, float healthPoints, FactionEntity source): called when a building’s health is updated by healthPoints, source presents the faction entity (unit/building) that caused this health update.

Upgrade Related:

  • UnitUpgraded (Upgrade unitUpgrade): called when a unit is upgraded by the upgrade component: unitUpgrade.
  • BuildingUpgraded (Upgrade buildingUpgrade): called when a building is upgraded by the upgrade component: buildingUpgrade.

Border Related:

  • BorderActivated (Border border): called when a border is activated.
  • BorderDeactivated (Border border): called when a border component is disabled/border is destroyed.
  • BorderResourcesUpdated (Border border): called when a border component’s list of resources inside its territory is refreshed.

Task Related:

  • TaskLauncherAdded (TaskLauncher taskLauncher, int taskID = -1, taskQueueID = -1): called when a task launcher component is activated.
  • TaskLauncherRemoved (TaskLauncher taskLauncher, int taskID = -1, int taskQueueID = -1): called when a task launcher component is disabled.
  • TaskLaunched (TaskLauncher taskLauncher, int taskID, int taskQueueID = -1): called when a task launcher launches a task under the index taskID.
  • TaskCanceled (TaskLauncher taskLauncher, int taskID, int taskQueueID): called when a task launcher cancels an in-progress task of index taskID and queue index taskQueueID.
  • TaskCompleted (TaskLauncher taskLauncher, int taskID, int taskQueueID = 0): called when a task launcher completes a task of index taskID.

Population Related:

  • CurrentPopulationUpdated (GameManager.FactionInfo factionInfo, int value): called when the current population of the faction in the slot factionInfo is updated by value.
  • MaxPopulationUpdated (GameManager.FactionInfo factionInfo, int value): called when the maximum allowed population of the faction in the slot factionInfo is updated by value.

Resource Related:

  • ResourceAdded (Resource resource): called when a resource is first initialized and registered in the Resource Manager.
  • ResourceEmpty (Resource resource): called when a resource is empty.
  • ResourceAmountUpdated (Resource resource): called when a resource’s amount is updated.
  • ResourceSelected (Resource resource): called when the player selects a resource.
  • ResourceDeselected (Resource resource): called when the player deselects a resource.

Faction Resource Related:

  • FactionResourceUpdatedd (ResourceTypeInfo resourceType, int factionID, int amount): called when a faction (with ID: factionID) has a resource (of type: resourceType) updated by amount.

APC Related:

  • APCAddUnit (APC apc, Unit unit): called when an apc adds a unit.
  • APCRemoveUnit (APC apc, Unit unit): called when an apc removes a unit.
  • APCCallUnits (APC apc, Unit unit = null): called when an apc calls units in range.

Portal Related:

  • UnitTeleport (Portal sourcePortal, Portal targetPortal, Unit unit): called when a unit is teleported from a sourcePortal to a targetPortal.
  • PortalDoubleClick (Portal sourcePortal, Portal targetPortal, Unit unit = null): called when the player double clicks on the sourcePortal to change the camera view to the targetPortal.

End Game Related:

  • FactionEliminated (GameManager.FactionInfo factionInfo): called when the faction under the the slot factionInfo is eliminated.
  • FactionWin (GameManager.FactionInfo factionInfo): called when the faction under the slots factionInfo wins a game.

Scenario Related:

  • ScenarioStart (Scenario scenario): called when the player loads a map scene with a scenario assigned to the Mission Manager component.
  • ScenarioSucess (Scenario sceanrio): called when the player completes all missions in the active scenario.
  • ScenariFail (Scenario scenario): called when the player one of the missions in an active scenario.

Mission Related:

  • MissionStart (Mission mission): called when the player starts a mission that belongs to an active scenario.
  • MissionComplete (Mission mission): called when the player completes a mission.
  • MissionFail (Mission mission): called when the player fails completeing a mission.

Custom Multiplayer Input Related:

  • CustomCommand (NetworkInput command): called when a custom input command is sent from the host/server in a multiplayer game.

Custom Events are also used by NPC components to monitor and control the NPC faction’s behavior.


Below is an example code of how we can use custom events. The same script is available in the asset under the name: CustomEventsExample.cs

How can we help?