This recipe shows how to set up the environment of UDK to allow our character to use an AnimTree we have been working on. While in the editor we can preview the AnimTree performance, that isn't the same as seeing it in action during gameplay. To deploy our AnimTree requires us to create a custom pawn class derived from the default pawn UDK includes. To do so, we first need to adjust some of UDK's configuration so it will accept the adjustments we're going to make.
The configuration steps are not very difficult, it is just that all the changes are made outside of the editor, an approach which may feel unfamiliar to designers used to working totally inside a software environment to produce content. In short, we just edit a few UnrealScript files to alert UDK to use our AnimTree when it loads. I am going to use a tool called ConTEXT for this example. This is a text editor which sits in the middle ground between Notepad and Microsoft Visual Studio. It is freely available from www.contexteditor.org and the Desktop Version is what I'll be using, along with its UnrealEd Highlighter template that can be found in the list at http://www.contexteditor.org/highlighters/.
This screenshot shows the simple, tabbed interface of ConTEXT, its convenient History list, and an open UnrealScript. Note that the UnrealScript Highlighter displays as UnrealEd in the icon row. Highlighters can be added by following the instructions from the ConTEXT website: To add a new highlighter to ConTEXT, download the highlighter and copy it to the Highlighters folder of your ConTEXT installation's folder. If ConTEXT is running, restart it to update the list of external highlighters. For full information on how ConTEXT works, look to their documentation. For us, it is only necessary to set the UnrealEd Highlighter to be active in an open document from the Select Active Highlighter list on the right-hand side end of the icon row.
Note that a dark blue background will be applied, which is a visual aid as it is easier on the eyes than a bright white color. If you are fond of changing colors, just edit the color entries in UEDScript.chl using HTML color codes (for instance CommentCol: clLime
could be replaced with CommentCol: $00FF00
) and you can find a list of color codes at http://www.w3schools.com/html/html_colors.asp. Bear in mind there is a foreground and background color pair that needs to be defined.
UDKGameContent
folder, you will need to create a folder called MyGame in the location: C:UDK~DevelopmentSrc
(where ~
is your version). The folder name MyGame can be any name but the upcoming code refers to it repeatedly, so you may find it helps to stick with this if you aren't sure you can track it all the way.C:UDK~DevelopmentSrcMyGame
, add a new sub-folder called Classes.C:UDK~DevelopmentSrcMyGameClasses
, create three new text files, MyGame.UC, MyPlayerController.UC, and MyPawn.UC, then right-click on each and choose Properties and ensure their Read Only checkbox is not ticked.What is MyGame anyway? When a designer creates a level, UDK requires a game type to be set, especially in later versions which no longer default to UTGame. The game type defines what kind of allocations hold out for the game, such as camera type, HUD used, details about the player, and everything that needs to be set at the entry point of the game.
C:UDK~DevelopmentSrcMyGameClassesMyGame.UC
. This will be empty currently. Paste in the following code to define how MyGame.UC configures the player:class MyGame extends UTGame config(MyGame); DefaultProperties { DefaultControllerClass = class'MyGame.MyPlayerController' DefaultPawnClass = class'MyGame.MyPawn' }
C:UDK~DevelopmentSrcMyGameClassesMyPawn.UC
. Treat lines in the code which are darkened as particularly important. Author comments are demarcated using //
and explain what follows. Type in the following code:class MyPawn extends UTPawn config(MyGame); //The Object class defined below provisions the player model. DefaultProperties { Begin Object class=SkeletalMeshComponent Name=SkeletalMeshComponent0 SkeletalMesh=SkeletalMesh'Package.Group.Asset' AnimSets(0)=AnimSet'Package.Group.Asset' AnimTreeTemplate=AnimTree'Package.Group.Asset' PhysicsAsset=PhysicsAsset'Package.Group.Asset' bEnableSoftBodySimulation=True bSoftBodyAwakeOnStartup=True bAcceptsLights=True End Object Mesh=SkeletalMeshComponent0 Components.Add(SkeletalMeshComponent0) //The setting below sets the apparent camera distance from its pivot, which is where the player model is located. The DrawScale of the pawn can be increased or decreased to suit, with testing. DrawScale=1 CameraScale=30 }
This code doesn't refer to specific character assets; they are listed only as Package.Group.Asset. It is important to realize code will vary according to different needs. Our examples will include only what's needed to produce a result for the problem of this chapter, using the Packt_SkinTailFBX character. The following section deals with referencing the existing SkeletalMesh assets to work with our own animation.
SkeletalMesh=SkeletalMesh
. Here's how the entries below that need to be adjusted for the character we've worked with so far in the chapter:// The top part of the code entered in the previous steps doesn't change, just the following lines:
SkeletalMesh=SkeletalMesh'Packt.Mesh.Packt_SkinTailFBX'
AnimSets(0)=AnimSet'Packt.Anims.Packt_SkinTailAnims'
AnimTreeTemplate=AnimTree'Packt.Anims.Packt_CharTree'
PhysicsAsset=PhysicsAsset'Packt.Mesh.Packt_CharPhysics'
C:UDK~DevelopmentSrcMyGameClassesMyPlayerController.UC
class MyPlayerController extends UTPlayerController; DefaultProperties { bBehindView=True }
MyGame
and its classes, and then test them out.C:UDK~UDKGameConfig
and open the file DefaultEngine.INI in ConTEXT.+ModEditPackages=MyGame
under the last entry in the section headed: [UnrealEd.EditorEngine]
(which you can search for using the menu command Edit | Find). The added line should come last because the list order determines the order that classes get loaded and compiled. Save the DefaultEngine.INI file.C:UDKUDK-2011-02DevelopmentSrcMyGameClassesMyGame.UC(16) : Error, Illegal character in name. Compile aborted due to errors.
In this case MyGame.UC contained a typo fault on line 16
; the line is found in brackets after the file name.
...MyPawn.UC(47) : Warning, ObjectProperty MyGame.MyPawn:DefaultMesh: unresolved reference to 'SkeletalMesh'Package.Group.Asset''.
The problem is that the asset is still in the abstract, not specifically one that exists such as SkeletalMesh'Packt.Mesh.Packt_SkinTailFBX. Again in ConTEXT, loading MyPawn.UC and using Ctrl + G to find line 47 would allow us to locate and fix this. Since you may periodically update the assets you want to use, this kind of oversight can easily occur.
C:UDK~UDKGameConfigDefaultEngine.INI
that points to your classes by adding ;
in front of the line +ModEditPackages=MyGame
.Z = -40
works well. The next screenshot shows this setting. Note in the small image that the character's feet are no longer on the ground line and she has dropped below. While this looks disconcerting in the viewer, in gameplay it looks okay.To provision the player model is a matter of telling MyGame.UC to use your MyPawn.UC and configuring UDK to use the MyGame folder. You should extend UTPawn.UC and set the default properties in the new MyPawn.UC class to those of your assets. There are plenty of examples of this on the UDK
forum www.udk.com/forums. An example using the asset Packt_SkinTailFBX is included in this book's provided content: /files/Development/MyGame/Classes/
.
After recompiling scripts, to place her in the scene as an NPC, place a Trigger actor and a PathNode actor. Create a Trigger event which connects to an Actor Factory action in Kismet. In its properties choose the Factory setting for an NPC by clicking [ ] and choosing UTActorFactoryAI then under it set the Controller Class to None and the Pawn Class to MyPawn, which should now show up in the list within the factory.
An example is in the provided map Packt_03_CheckMyPawnworks.UDK.
18.223.133.169