Controllers
The EntityController
is a core building block for creating gameplay in the FPS Template. It contains the default configuration for a specific entity and every entity is assigned exactly one controller. All controllers are stateless and roll-backable data is stored, as always, in Quantum state (i.e. in a component). Scene entities always have a dedicated controller instance, entities created from an entity prototype at runtime always reference the same (prefab) controller instance.
Controllers are classes and can implement interfaces, which is a recommended development technique when extending functionality of a specific entity.
Controllers are created in Quantum solution by:
- Deriving from existing controllers provided by the FPS Template, execution is driven by corresponding systems (
ActorController
-ActorSystem
,WeaponController
-WeaponsSystem
,AbilityController
-AbilitiesSystem
, ...):public class ExplosionController : UpdatableActorController
public class ProjectileWeaponController : WeaponController
public class GrenadeAbilityController : AbilityController
- Deriving from the base
EntityController
; this requires you to create a custom system to drive the execution of the controller's main logic
In the following diagram the interface of a generic UpdatableActorController
and execution paths are presented.
Following diagram shows execution paths of HealthAreaController
:
This is what happens throughout health area entity lifetime:
- When health area is being spawned, all interested systems (implementing
ISignalInitializeEntity
) are notified of the entity creation (the order is defined bySystemSetup
). - The
ActorSystem
checks if the entity controller is derived fromActorController
and invokesInitialize()
on it. - The
ActorSystem
checks if the entity controller is derived fromUpdatableActorController
and adds theUpdatableActor
component; adding/removing ofUpdatableActor
is completely driven by the system at runtime, it is not possible to manage it manually from Unity. HealthAreaController
is responsible for adding all relevant components (HealthArea
in this case) and initializing it.InteractionsSystem
checks if the entity controller implements any interface which the system is responsible for (in this caseIInteractableTriggerController
), adds theInteractableTrigger
component and initialize it; this component is runtime only and handled solely byInteractionsSystem
, however it is allowed to read its data from outside.- When an entity enters a health area -this depends on the physics configuration of both entities-, the
OnTriggerEnter3D
signal is fired fromPhysicsSystem3D
.InteractionsSystem
reacts to the signal and forwards it to theHealthAreaController
where the logic decides if the triggering entity is valid or not. Allowed entities are maintained byInteractionsSystem
in theInteractableTrigger
component. - When an entity leaves a health area (based on
OnTriggerExit3D
) or the entity is destroyed,InteractionsSystem
invokesOnExit()
on theHealthAreaController
. - Every update, the
ActorSystem
iterates over all entities with anUpdatableActor
component and invokesUpdate()
on the corresponding controllers. - When entity gets destroyed, the
ActorSystem
invokesDeinitialize()
on theHealthAreaController
which is responsible for correctly cleaning up the entity.
The FPS Template supports several interfaces which can be used to extend entity behavior; these are explained separately in their corresponding systems.
Back to top