Search public documentation:


Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Unreal Development Kit Gems > MOBA Starter Kit > Weapon System

MOBA Starter Kit - Weapon System

Last tested against UDK May, 2012


The weapon system in this Starter Kit differs from the standard weapon system in UDK. This is because the complexities of the weapon largely relied on the stats of the creep, hero or tower; rather than within the weapon itself. This, instead of having most of the data stored within the weapon code, weapons act more like a notification system where they collate data from the stats system and then negatively apply the data to enemy creeps, heroes or towers.


This is the base abstract weapon fire mode class. This sets up most of the base functions and variables used by the child classes so that there is a common interface for all other classes that need to interact with weapons.


  • SetOwner() - This sets the owner of the fire mode. This is needed by the fire mode, because as an object it does not store any information about location, rotation and so forth. Thus for weapons to interact with the world, they need to know the owner who is an Actor (more likely to be a Pawn).
  • GetAttackingAngle() - This returns the attacking angle of the weapon. This allows weapons to have "fuzzy" aiming where Pawns do not have to aim precisely at other Pawns in order to fire the weapon.
  • Destroy() - This cleans up the fire mode object so that it can be removed by the garbage collector. It is important to clean up the object and null any references to Actors and Objects.
  • StartFire() - This initiates firing of the weapon. This works by setting up a timer within the owner (set by SetOwner()), and then the timer fires the weapons according to the firing rate which itself is influenced by the AttackSpeed stat.
  • StopFire() - This stops the weapon if it is currently firing by clearing the timer.
  • IsFiring() - This returns true if the timer set up in StartFire() is currently active or not. If it returns true, then the weapon is firing.
  • Fire() - This function performs the actual firing of the weapon. This is called by the timer set up in StartFire().
  • BeginFire() - This is the protected function that sub classes should implement to perform their own specific method of firing weapons.


  • WeaponOwner - This is a reference to the Actor, that implements UDKMOBAAttackInterface, which owns this weapon.



  • BeginFire() - This function overrides the BeginFire() function declared in UDKMOBAWeaponFireMode::BeginFire(). This function works by first grabbing all of the actors that are within the 'cone' of detection. This cone is defined by first getting all of the Actors within range by using the VisibleCollidingActors() iterator. Every Actor within this circle, is then checked if they are within the dot angle. This check creates the edges of the 'cone'. If there is no maximum hit count specified then all of the Actors detected are damaged. Otherwise, the detected Actors are rated and sorted, and then the highest rated Actors are damaged.
  • CompareHitActors() - This function is used by dynamic arrays to handle sorting.


  • Range - This is the maximum range of the weapon.
  • Extent - This is the extent trace of the weapon which is used by the VisibleCollidingActors() iterator.
  • DotAngle - Dot angle that the hit actor has to be within to count as a hit. The closer to 1.f this value is, the more 'accurate' the weapon is.
  • HitCount - Maximum number of actors to hit.
  • MomentumTransfer - Momentum to transfer to all actors that are hit.



  • BeginFire() - This function overrides the BeginFire() function declared in UDKMOBAWeaponFireMode::BeginFire(). This function simply spawns a projectile based on the ProjectileArchetype value. After setting up the projectile, it is then initialized and launched towards the enemy.


  • ProjectileArchetype - Archetype of the projectile to use when firing this weapon.


This is a specialized projectile class used by UDKMOBAWeaponProjectileFireMode.


  • PostBeginPlay() - This event is called when the projectile has been instanced and initialized by Unrealscript.
  • ReplicatedEvent() - This event is called when a variable flagged with rep notify has been replicated to the client. This event catches when the Enemy variable is replicated. When it does arrive on the client, it starts the homing timer so that the projectile also homes in on the target on the client side.
  • Init() - This sets the velocity of the projectile and also starts the homing timer.
  • HomingTimer() - This first checks if the enemy variable is none or is invalid to attack, if it is then the projectile is destroyed. Otherwise, it will reorient the projectile's velocity so that it seeks towards the enemy.
  • Touch() - This ensures that the projectile only responds to touch events that involve the enemy.
  • ProcessTouch() - This ensures that the projectile only deals damage and explodes when the projectile touches the enemy.
  • HitWall() - This ensures that the projectile only deals damage and explodes when the projectile touches the enemy.
  • DealEnemyDamage() - This applies damage to the enemy.
  • Explode() - This handles when the projectile explodes. It plays the impact sound, spawns the particle effect and instances a decal.


  • FlightParticleSystem - Particle system to instance when the projectile is flying through the air. This is often used to represent the projectile itself.
  • ImpactTemplate - Particle system to instance when the projectile collides with its target.
  • ImpactDecalMaterialInstanceTimeVarying - Impact material instance time varying to use for decals. This assumes the linear scalar data is setup for fading away.
  • ImpactDecalOpacityScalarParameterName - Impact opacity scalar parameter name. This parameter name should exist in the decal material or nothing will happen.
  • ImpactDecalLifeSpan - Impact decal life time in seconds.
  • ImpactDecalMinSize - Impact decal minimum size.
  • ImpactDecalMaxSize - Impact decal maximum size.
  • AlwaysUniformlySized - If true, then the size of the decal is always uniform (square).
  • Speed - Defines the initial velocity of the projectile.
  • MaxSpeed - Limit on speed of projectile (0 means no limit).
  • SpawnSound - Sound made when projectile is spawned.
  • ImpactSound - Sound made when projectile hits something.



  • BeginFire() - This function overrides the BeginFire() function declared in UDKMOBAWeaponFireMode::BeginFire(). This function uses the Trace() function to find an Actor to hit.


  • TraceRange - This is the maximum range of the weapon.
  • TraceExtent - Box extent to use for the trace.
  • MomentumTransfer - Momentum amount to transfer to hit actor.

How do I add a weapon to my hero/creep?


Because of this simplified weapon system, you only need to create new weapon fire mode objects within the pawn archetype itself. When you create a new UDKMOBAHeroPawn archetype for example, you use the properties window to instance a new weapon fire mode of the type that you want and then assign the various properties.

How do I create new fire modes?

Creating new fire modes requires you to create new sub class of UDKMOBAWeaponFireMode. Most of the time, it is the BeginFire() function that you will need to subclass to insert your own firing logic.

class YourNewFireMode extends UDKMOBAWeaponFireMode;

 * Fires the weapon.
 * @param      FireLocation      Where in the world the weapon should fire from
 * @param      FireRotation      Direction the weapon should fire in
 * @param      Enemy            Enemy to shoot at
 * @network                     Server
protected function BeginFire(Vector FireLocation, Rotator FireRotation, Actor Enemy)