Skip to main content

Customization

Teams, tuning, damage and multiplayer. The names of all properties and functions are in the Blueprint Reference.

Teams​

Every turret has a TeamID (byte, 255 = no team). The controller copies it from the turret it possesses and decides with the engine's default rule:

Other actorAttitude
Pawn of the same teamFriendly, ignored
Pawn of another teamHostile, attacked
Pawn without a teamHostile, attacked
Anything that is not a pawnNeutral, ignored

Giving the player a team​

A pawn has a team when it, or its controller, implements BPI_TeamAgent → GetTeamID. Either:

  • set Blueprints/Examples/BP_TeamPlayerController as your GameMode's Player Controller Class and set its TeamID, or
  • add BPI_TeamAgent to your own controller or pawn (Class Settings → Interfaces) and implement GetTeamID.

Changing teams at runtime​

Turrets do not notice team changes on their own. After changing a team, call OnTeamsChanged on every BP_TurretAIController, as BP_TeamPad does.

Your own friend/foe rule​

Create a child of BP_TurretAIController, override GetTeamAttitude and return the attitude you want. BP_TurretAIController_AlwaysFriendly returns Friendly for everyone. Set your controller as the turret's AI Controller Class.

Tuning​

Detection range and field of view​

Open the controller (for example a child of BP_TurretAIController), select the AIPerception component and go to AI Perception → Senses Config → Index [0] → Sense:

  • Sight Radius: maximum detection distance
  • Lose Sight Radius: keep it a little higher than Sight Radius
  • Peripheral Vision Half Angle: 90° gives a 180° field of view

Fire rate and tracking​

On BP_TurretAIController:

PropertyDefaultMeaning
ShootProjectileTimerRate0.7Seconds between shots
TrackPlayerTimerRate0.1Seconds between aim updates
TrackingTimeout3.0Seconds without a hostile in sight before the turret resets
ShootingActive, TrackingActivetrueSwitch firing or tracking off

Projectile speed and barrels​

On the turret:

PropertyMeaning
VelocityScaleProjectile speed in cm/s. The base class uses 1000, the two turrets 4000
bDualBarrelFire from both barrels
DualBarrelShootDelayDelay of the second barrel
ProjectileClassProjectile to spawn, BP_TurretProjectile by default

The lead calculation uses VelocityScale, so faster or slower projectiles still hit.

Projectiles expire after 5 seconds (InitialLifeSpan on BP_TurretProjectile): 200 m at 4000 cm/s. Raise it for turrets that fire farther.

Health and damage states​

On the turret's HealthComponent (AC_Health): MaxHealth (default 100) and bDamageImmune.

Damage states are three parallel arrays on the turret: DamageStateThresholdPercentages (0.75, 0.5, 0.25), DamageStateEffectClasses (BP_DamageState_Sparks, _Smoke, _Fire) and DamageStateEffectOffset. Add, remove or replace entries to change them. The debris actor is DestroyedActorClass.

Damage​

Turrets take damage through the engine's Apply Damage, so any Blueprint can damage them. ChangeHealth on AC_Health heals with a positive value.

The turret's projectiles deal no damage by default. OnProjectileImpact on BP_TurretPawnBase is empty. To make them hurt:

  1. Create a child of BP_TurretPawn (or open your own turret).
  2. Override the function OnProjectileImpact.
  3. Call Apply Damage with OtherActor as the damaged actor.
Multiplayer

Every machine spawns its own projectiles, so OnProjectileImpact runs on every machine. Put a Has Authority check in front of Apply Damage, or clients apply the damage too.

Health, damage feedback and destruction can be reacted to through the dispatchers on AC_Health: OnHealthChanged, OnDeathStarted, OnDeathFinished.

Multiplayer​

  • Health and death state replicate. Damage states, damage numbers, the health bar and destruction run on clients through RepNotifies.
  • Shots are a multicast: every machine spawns its own, unreplicated projectiles.
  • The turret's aim (TurretRotation) replicates.

The example map has been played in multiplayer by hand. There is no automated multiplayer test.

Your own turret model​

  1. Create a child of BP_TurretPawnBase.
  2. On MeshComponent, set your skeletal mesh and an Animation Blueprint that rotates the head from the turret's TurretRotation (see ABP_Turret).
  3. Add sockets for the muzzle and, for two barrels, a left and right muzzle. Set their names in Name_SocketMuzzle, Name_SocketMuzzleLeft and Name_SocketMuzzleRight (defaults muzzle, muzzle_left, muzzle_right).
  4. Set AI Controller Class to BP_TurretAIController or a child of it.

Effects and sounds​

On the turret: ShootSound, ResetTurretSound, DamageSound, DestructionSound, MuzzleFlashEffect and ProjectileEffect. Override SpawnShootFX for a custom muzzle effect.

Things to know​

  • A turret's own shots fly through each other, so the converging shots of a dual-barrel turret do not collide. Shots of different turrets do collide.
  • Aiming assumes a target standing on the turret's floor. The turret aims at a Character's feet, and the muzzle height lifts the shot into the capsule. Flying or small non-Character targets are overshot by about the muzzle height.
  • Turrets can be scaled. The health bar, damage numbers and debris follow the actor scale. HealthBarHeight is given at scale 1.