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:

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.

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.

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).
  • UnitConverted (Unit unit, Unit targetUnit): called when a unit is 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.
  • 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.

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<Unit> unitUpgrade): called when a unit is upgraded by the upgrade component: unitUpgrade.
  • BuildingUpgraded (Upgrade<Building> 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.

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:

  • ResourceEmpty (Resource resource): called when a resource is empty.
  • ResourceSelected (Resource resource): called when the player selects a resource.
  • ResourceDeselected (Resource resource): called when the player deselects a resource.

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.

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?