Friday, October 14, 2011

Pawn Class (UnrealScript)

The Pawn class is used to physically represent the players, characters and creatures in the Unreal Engine. It contains functionality for dealing with 3D models (Mesh), animation, collision, damage, physics, weapons, sound...

An object of type Pawn can be controlled by a player or by Artificial Intelligence. This control is encapsulated in a class of type Controller and is indifferent to the Pawn class. In the next article we will see the use of the Controller class.

There are several subclasses of Pawn in the Unreal Engine as seen in the image below. We can see that the Pawn class is also used to create vehicles. Classes that begin with UT contains the implementations for the game Unreal Tournament.


I did a very simple example to illustrate the use of the Pawn class. I create a subclass of UTPawn class that can be place by the editor. I added a SkeletalMeshComponent (3D model with animation) and set the properties required for the animation. Then, I define that my class will be controlled by a Controller class of type UTBot.

class TestPawn extends UTPawn
      placeable;

defaultproperties
{
   begin object class=SkeletalMeshComponent Name=Model3D                
      SkeletalMesh=CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode
      PhysicsAsset=CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics
      AnimSets(0)=CH_AnimHuman.Anims.K_AnimHuman_BaseMale
      AnimtreeTemplate=CH_AnimHuman_Tree.AT_CH_Human
   end object

   Components.Add(Model3D);
    
   ControllerClass=UTGame.UTBot
}

This screenshot is from my test using this class and running on the UDK Editor: