Time for action – Examining inheritance
We can see an example of this by taking a look at the class tree in UnCodeX, under Actor | Inventory | Weapon | UDKWeapon. Expanding UTWeapon we can see the different types of weapons provided as examples in the UDK:
We can see that
UTBeamWeapon
(like the plasma gun we start with when running the game),UTWeap_RocketLauncher
, andUTWeap_ShockRifleBase
are amongst our weaponry. Each of these behaves differently, but all of them have common functionality.Clicking on
UTWeapon
, we can see some of its variables./** Initial ammo count if in weapon locker */ var int LockerAmmoCount; /** Max ammo count */ var int MaxAmmoCount; /** Holds the amount of ammo used for a given shot */ var array<int> ShotCost;
What just happened?
Things like MaxAmmoCount
and ShotCost
are common to all of the weapons, so instead of having to duplicate the variables to all of the subclasses, they're declared in all of the weapons' parent class, UTWeapon
. Indeed, if we...