Chapter One – Creating the Player Controller

February 4th, 2010 Leave a comment Go to comments

Now that you have a valid and compiling game shell, its time to spice things up. Again create a new class following the same instruction as with the GameInfo class (see Creating Script Files for reference.). Name the new file “IsometricGamePlayerController”.

 

You should now have again a class that extends Object as the following image :

 

Game_IsometricGamePlayerController

 

Now Change the extends Object to GamePlayerController. What is the Game Player Controller ? It handles user inputs and is specifically geared toward controlling a single avatar which represent the persona of the player in the 3d world you create with UDK.

So when you move the mouse and shoot, things will be computed in this class as a starting point. This class will hold our artificial intelligence to give our pawn basic functionality you would expect from a modern game such as path finding.

The first thing you will want to add is a test function to be sure everything is wired correctly from your game info to your player controller. Add the following function under the class declaration and the DefaultProperties keyword.

 

simulated event PostBeginPlay()

{

super.PostBeginPlay();

`Log(“I am alive !”);

}

 

Now this function is executed automatically when play begin and on a “RestartLevel” console function. The super directive tells that you will execute the function in the parent. This is important if the parent class was doing something, its better to keep doing it again and also add our own code afterward. This is called function overloading. If your not familiar with this, look it up by yourself because its not part of this tutorial.

Now to wire our player controller to our game, we need more than just create a new class. We need to actually instruct our GameInfo class to use this new player controller. This is done by using the DefaultProperties of the IsometricGameInfo class. Return to the GameInfo class inside Visual Studio. Now DefaultProperties are use to specify default values for member variables of a class.

 

For example we will specify a new class to use as PlayerController. When the IsometricGameInfo will be created by the UDK, it will look to this variable to know which class name to use to create a new player controller. This process is hidden away in the code somewhere, you can look it up to satisfy your curiosity its located on line 1097 of GameInfo.uc.

 

 

Add the following entry :

DefaultProperties

{

PlayerControllerClass=class‘IsometricGamePlayerController’

}

 

CORRECTIONS 04 feb 2010 : PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’ (end of chapter source code has this fix)

 

The class instruction tells the compiler that you are actually specifying a class type, specified by the text inside the quotes.

  • Hit the play button and inspect the log

 

 

So it is alive if you look at the line before the ########## Finished loading level...

So it is alive if you look at the line before the ########## Finished loading level...

 

 

 

Chapter One – Creating the Isometric camera

 

 

 

Update me when site is updated
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • PDF
  • Twitter
  1. Shad
    December 20th, 2009 at 19:15 | #1

    Une petite traduction francaise faite rapidement ! ^^ Ca peut peut être faire gagner du temps !

    Merci pour ce tuto.

    ———

    Maintenant que vous avez une base de jeu valide qui compile correctement, il est temps d’aller un peu plus loin. En suivant les même instructions que pour la classe “GameInfo”, créez à nouveau une nouvelle classe, et nommez le nouveau fichier “IsometricGamePlayerController”.

    Vous devriez obtenir une nouvelle classe héritée de “Object” comme le montre l’image suivante :

    Désormais, changez l’héritage de “Object” pour “GamePlayerController”. Qu’est ce qu’un “GameController” me direz-vous ? Cela permet de tenir compte des touches sur lesquelles appuis l’utilisateur et il est particulièrement utile pour contrôler un avatar unique qui représente la personne du joueur dans le monde en 3D que vous créez dans l’UDK.

    Donc, quand vous bougez la souris et que vous cliquez, les choses commencent dans cette classe. Cette classe va permettre à notre Intelligence Artificielle de donner a notre “Pawn” des fonctions de bases (tel le “Path Finding”) de tous les jeux modernes.
    La première chose que vous allez avoir envie d’ajouter est une fonction de test pour être sur que tout est correctement connecté depuis le “Game Info” jusqu’au “Player Controller”. Ajoutez la fonction suivante entre la déclaration de classe et le mot clé “DefaultProperties”.

    Désormais, cette fonction sera exécutée automatiquement lorsque le je commencera et sur entrée dans la console de la ligne de commande “RestartLevel”. L’indication “Super” permet d’exécuter la même fonction de la classe parent. C’est important si la classe parent faisait quelque chose, de garder ce qu’elle faisait, et d’y ajouter son propre code a la suite. C’est ce que l’on appelle “Function Overloading”. Si vous nêtes pas familier avec cela, prenez le temps de vous renseignez car cela ne fait pas partie du tutorial.

    Cependant, relier notre “Player Controller” à notre jeu requière plus que la simple création d’une classe. Nous devons indiquer à notre GameInfo d’utiliser le nouveau “Player Controller”, cela en utilisant les “DefaultProperties” de la classe “IsometricGameInfo”. Retournez à la classe “GameInfo” dans Visual Studio. Les “DefaultProperties” sont utilisées pour spécifier des valeurs par défaut aux différentes variables d’une classe.

    Par exemple, nous allons spécifier une nouvelle classe à utiliser comme “PlayerController”. Quand la “IsometricGameInfo” va être créée par l’UDK, il va chercher à cette variable pour savoir quelle nom de classe utiliser comme nouveau “Player Controller”. Ce processus est caché quelque part dans le code : vous pouvez aller y jetez un œil si vous voulez satisfaire votre curiosité, à la ligne 1097 du fichier “GameInfo.uc”.

    Rajoutez donc la valeur suivante :

    L’instruction de classe va dire au compilateur que vous êtes actuellement en train de spécifier un type de classe, par le texte entre guillemets.
    - Appuyez sur le bouton “Play” et inspectez votre “log”.

    Donc il est “Alive” si vous regardez la ligne avant le “########## Finished loading level”.

  2. Hotdot
    December 20th, 2009 at 22:23 | #2

    Merci Shad :) toute l’aide reçu est bienvenue !

  3. CaRteR
    December 31st, 2009 at 05:51 | #3

    I can’t get this to work. The code keeps failing in the build. (I wish I could read what the prior commenter said.)

  4. Daiboken
    January 16th, 2010 at 15:41 | #4

    There is an error with
    {

    PlayerControllerClass=class‘IsometricGamePlayerController’

    }

    Should be replaced with PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    PD: Many thanks to the author of this tutorial, it is helping me a lot :)
    This is why are you can’t get this to work Carter :)

  5. Hotdot
    January 17th, 2010 at 22:29 | #5

    Daiboken, maybe a UDK error, without the path for class’… works fine for me right now, you can specify it or not, its optional it seems.

  6. kugz
    February 2nd, 2010 at 11:05 | #6

    hey daiboken what version of the udk are you running cause ur solution is giving me the same error as the the original error. No disrespect to the author loving the tutorials but extremely hating this tiny errors brought about by using different versions of the udk

  7. Floboy
    March 15th, 2010 at 16:27 | #7

    Hey great tutorial but im stuck at this part , when i play at the end the game crashes and i log after Finished loadin level , i get
    ScriptLog: Couldn’t spawn player controller of class None
    Warning: Login failed: Engine.GameMessage.FailedSpawnMessage
    Critical: appError called: Could not spawn player
    Critical: Windows GetLastError: The system cannot find the file specified. (2)

    ive done just like in the tutorial :D im a noob with script so bare with me :D

  8. Hotdot
    March 15th, 2010 at 22:51 | #8

    did you use the fix for february release, it would seem that from the march version of UDK, the scripting require the folder as prefix to your class like the following :

    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    you can also always download the source code further down to check your file against the code that was tested. Your problem is pertaining to the playercontroller class not being created, so the main character cannot spawn and gives an error.

  9. David
    April 8th, 2010 at 23:46 | #9

    so i guess im still completely lost, i cannot for the life of me get anything to post to the cmd line script at all. any ideas why it might not post like its supposed to? (using march release of UDK atm just to clarify)

  10. Roychr
    April 12th, 2010 at 18:42 | #10

    David, to enable the command line console, you have to enable it in the projects settings of the unrealscript solution inside visual studio. Fall back to chapter 0 and be sure to set up the project properly, there are 3-4 options when launching from visual studio like disabling starting epic splashscreen, enabling console and some others. Its on the same page as where you specify your launching map. Hope I am answering to your question :)

    cheers !

  11. Effregy
    May 9th, 2010 at 04:05 | #11

    Despite using the fixed code version” PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’ ”
    I get
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’

  12. Moriteza
    May 12th, 2010 at 14:53 | #12

    @Effregy
    Dear Effregy u should use this script :
    class’MyIsometricGame.IsometricGameInfo’

  13. Neurotiq
    May 16th, 2010 at 11:23 | #13

    @Moriteza
    heres the problem.

    The UDK or UT Game.ini and UDK or UT Engine.ini have a glitch in them.

    I deleted my entire UDKGame folder then reinstalled UDK. Then did the first chapter over.
    It worked. The entry for game type is right at the top, and MyMod is easy to find because of the “;”

  14. Roychr
    May 18th, 2010 at 15:48 | #14

    This is hard trying to correct ghost bugs that are sometimes caused by the BETA state of UDK. Thanks Neurotiq.

  15. KlaarX
    June 2nd, 2010 at 06:25 | #15

    I had to write :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    instead of :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    to make this tutorial work with the UDK May release.

    Hope it will help.

  16. KlaarX
    June 2nd, 2010 at 06:27 | #16

    I had to write :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    instead of :
    PlayerControllerClass=class’MyIsometricGame.IsometricGamePlayerController’

    to make this tutorial work with the UDK May release.

    Hope it will help.

  17. Mohannad
    June 23rd, 2010 at 13:54 | #17

    @KlaarX
    You are typing the same lines in fixed lines and the original, i see no difference, or am i blind? im using UDK May Release also and its still not working for me sadly, I get
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’ Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’

    still cant understand why >.<

  18. Mohannad
    June 23rd, 2010 at 16:44 | #18

    I managed fixing that, but now on the SCriptLog, I keep getting this error

    Cannot spawn player controller of class None

  19. June 23rd, 2010 at 17:24 | #19

    @Mohannad
    The quotes dont copy correctly, try retyping the single and double quotes on any line that has em.. i fixed these issues that way in mine. It happens when u copy over the code.

  20. June 23rd, 2010 at 17:48 | #20

    @Neurotiq
    oi, lol

    @*
    I have this working, about to move on to next stage, but am I supposed to be able to see the player model in this already cuz I can, the camera is inside him… following instructions to the letter, using VStudio2008+nfringe & May2010 UDK.. extending GameInfo not UTGame.

    ANOTHER BIG QUESTION,
    Since using nfringe with this setup before May2010 and then again after may 2010 UDK installation, I now get the following warning… shit still works, .u’s still get made from the .uc’s and all but the msgs worry me:

    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWCamera.uc’ is not located in a folder recognized by the script compiler.
    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWGameInfo.uc’ is not located in a folder recognized by the script compiler.
    UnrealScript.targets(0,0): warning : The script file ‘Classes\DWPlayerController.uc’ is not located in a folder recognized by the script compiler.

    Like I said they are getting compiled but something about the way we are using the things together seems to be lopsided/broken, any ideas?

  21. stephen
    June 29th, 2010 at 16:40 | #21

    I have tried everything, but no matter what I do, I get:
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Log: Game class is ‘GameInfo’

    I have tried every possible option posted, I tried typing everything in manually, I tried copying your code directly, I even tried overwriting my code with your sourcecode.

    Any help would be appreciated.

  22. FuzzeWuzze
    September 11th, 2010 at 17:49 | #22

    FYI Stephen, or anybody else that reads this i think i know the problem.

    Im having other problems now but ill see if i can help yours atleast.

    When you create the VS project, make sure you uncheck “Create project in folder” or whatever the option is.
    Unless you do this VS buries you MyIsoMetricGame\Classes folder inside another MyIsometricGame folder, so UDK doesnt know where to look for it.

    It builds src\MyIsometricGame\MyIsometricGame\Classes, it should be src\MyIsometricGame\Classes. Simply moving the folders doesnt really work either as VS will look for them in that path still, best to remake a new one and copy in your classes folder.

  23. RedFuser
    October 3rd, 2010 at 15:33 | #23

    Hi, thanks for the tutorial. After a whole day of tearing my hair out I’ve come to one and last problem with this line:
    `Log(“I am alive !”);

    If I have it uncommented, it prevents me from compiling the project and starts showing tons of errors, and if I comment it, everything compiles and works perfectly. Any ideas?

  24. October 10th, 2010 at 09:25 | #24

    “not located in a folder recognized by the script compiler”
    For those of you who have encountered this problem you should go to your UDKEngine.ini file and search for the EditPackages lines. There you should add a new line ModEditPackages=NameOfYourProject in the case of this tutorial ModEditPackages=MyIsometricGame this is done to add the new package you are creating so UDK can add your classes and compile them. Build should succeed without any problems, but if you still get any warnings in the Log Console check your directory structure.
    Also check the console for this line – Log: Game class is ‘IsometricGameInfo’
    Most helpful thing for this was http://udn.epicgames.com/Three/DevelopmentKitFirstScriptProject.html#ProjectSetup

  25. Roychr
    October 20th, 2010 at 21:23 | #25

    Just want to buzz around and say thanks to people commiting to giving helpfull advice on how to fix these problems. I just hope UDK gets out of Beta state so the API stops changing every months !

  26. Syndrome9001
    January 9th, 2011 at 19:38 | #26

    I just found UDK and so far it seems pretty cool. I’d really like to continue this tutorial but I ran in to a problem with the line:

    simulated event PostBeginPlay()
    {
    super.PostBeginPlay();
    ‘log(“I am alive !”);
    }

    While compiling (with ConTEXT, not nFringe) it says there’s an “Illegal character in name”. I’m using the latest UDK (dec. release) and the latest ConTEXT and have it set up to work just like nFringe (I think.)

    I’ve never scripted anything before and I haven’t been able to find any other script examples that may help. Does anyone have any idea what’s wrong?

  27. Syndrome9001
    January 9th, 2011 at 19:55 | #27

    SUCCESS! I figured out the problem already after opening the UTPlayerCtontroller.uc and doing some research

    I had written a “‘” quotation mark instead of “`” the tilde key before “log”… should have just copy and pasted from this tutorial lmao. Oh well, good learning process…

  28. Kien
    February 14th, 2011 at 16:49 | #28

    I get the following error if I compile:

    C:\UDK\UDK-2011-01\Development\Src\UDNGame\Classes\UDNPlayerController.uc(7,0): error : Bad or missing expression in Call to ‘LogInternal’, parameter 1

    Can anybody help me with this?

  29. roychr
    February 14th, 2011 at 16:54 | #29

    Is this the newest February BETA ?

  30. larles
    February 22nd, 2011 at 08:38 | #30

    @roychr I have the same error (bad or missiong expression in Call `LogInternal`) and I’m using the latest BETA (february 2011)
    Any idea ?

  31. admin
    February 22nd, 2011 at 10:55 | #31

    This could be that they changed the Log function but I cannot see the changes anywehre for that. Be sure to put the “‘” character before the Log command it is mandatory and not a typo.

  32. nickel
    March 28th, 2011 at 01:45 | #32

    Hey,
    For all those people getting errors on the “I am alive” part.
    Did you copy and paste? I was getting errors (the ‘logInternal’parameter 1) until I deleted the block and re-typed it manually. Then it worked fine.

  33. Cob
    April 12th, 2011 at 13:32 | #33

    Some characters used in the code here are outdated/wrong. I changed the following to compile;

    `Log(“I am alive !”);
    Should be
    `Log(“I am alive !”); ( Check the Tilde and the double quotation characters!)

    PlayerControllerClass=class‘IsometricGamePlayerController’;
    Should be
    PlayerControllerClass=class’IsometricGamePlayerController’ (Check quotation characters!)

  34. Psy
    May 25th, 2011 at 15:04 | #34

    I get the same error as the other guy and I’ve searched and searched over the past 2 hours without any inkling of solving the issue.

    The error is…

    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Warning: Warning, Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’
    Log: Game class is ‘GameInfo’

    Help! :(

  35. Pfhreak
    September 28th, 2011 at 14:23 | #35

    Anyone stuck with the ‘Warning: Warning, Failed to load ‘Class MyIsometricGame.IsometricGameInfo’: Failed to find object ‘Class MyIsometricGame.IsometricGameInfo’

    Go back and check to make sure you’ve edited your inis correctly:

    Open the file UDK\UDKGame\Config\UDKEngine.ini and look for the section called [UnrealEd.EditorEngine]. In this section you see some entries called EditPackages. These are the default packages the compiler will consider for compiling. EditPackages are reserved for the base UDK packages, custom packages should be added as ModEditPackages.

    Thus for the MyIsometricGame package the entry ModEditPackages=MyIsometricGame should be added.

  1. September 2nd, 2011 at 10:03 | #1
You must be logged in to post a comment.