Monday, November 12, 2012

Set-up UDK for Programming with UnrealScript

 So there are couple of necessary steps you have to make before you can start developing the game of your dreams with UDK. Captain Obvious was assisting me on writing this article.
  1. Download UDK
  2. Install UDK
  3. Download an IDE
  4. Install the IDE
  5. Create folder for your classes.
  6. Add entry about the folder to UDK .ini file
  7. Create BuildGame shortcut.
  8. Create batch file

Now when you know what we need to do, let's do it!

Get UDK

Latest version of UDK can be downloaded from here:
At the moment of writing November 2012, was the latest. It is also the first one to introduce Clean Starter Project Tool. So do not be surprised or confused once you see this message:
Difference between those is that in the first case UnrealTournament will be installed with all the graphical assets and code, both of which can be helpful both to analyze and reuse. My advice is go with the SampleGame install. Both cases work for following the tutorials on this blog, because even though I do read UT code from time to time, I never use (read "extend") them. The rest of the installation should be ordinary, unless they add some other stuff in later versions.
By the end of the installation though, you will be asked if you would like to install version control tools. We don't need them for now.

Get an IDE

IDE stands for Integrated Development Environment! I know that because I Googled it! Shortly it's the program that will help us write code! One might have thought (I did) that UDK has some built in coding tool (like say Flash), but it doesn't. You need something that will edit class files.

Classes are simple text files. You can use Windows Notepad for the job! But IDEs help you read and write the code better and faster. 
My study process went much faster once I switched from UnCodeX to VisualStudio+nFringe. But then I found this Unreal Script IDE which almost the same as VisualStudio+nFringe, but it comes in one package and is free. (nFringe is only free for non-commercial use) 

You can get it here: 

Now listen to me very carefully! Do NOT "Next, Next, Next"!!! Depending on what was installed on your machine before the installation might take long time or it might take couple of seconds.
Once it comes to "Select UDK Binary Win32 Folder" select path to Binaries\Win32 folder within your UDK installation. 
God I hope you remember where installed it! By default it's right in C:\.

Once the installation is over run the Unreal Script IDE, there should be an icon created on your desktop. Now, does your Solution Explorer in the right side of the screen look somewhat like this? If you did SampleGame installation of UDK, then you should have more folders and files here, but what matters is that it shouldn't be empty!

If it is empty, try reinstalling and make sure you've done "listen to me very carefully" part right. 
This page might also help you if you're having problems:  


Create folder for our work!

Some of the following steps can be done from UnrealScriptIDE, but I won't use it in case you choose some other IDE for your work. 
Go to your UDK folder! If you don't see 4 folders: Binaries, Development, Engine, UDKGame, then go into the folder with date in its name.(or the folder might be called Custom or something you called it if you did the EmptyGame installation) Hopefully now you see the folder!
Go to Development\Src. Here you will create folder for your project! Call it whatever you want, make it meaningful, don't make it long! You might gonna have to type this name a dozen of times later.
So let's say we created a folder called UnrealGame
Create folder called Classes inside of it.

UDK doesn't really like totally empty folders so... Open notepad and let's quickly create our first class! 
Copy/paste the following lines into your Notepad. Save the file as UnrealGameInfo.uc in the Classes folder we have just created! (don't forget to switch Save As Type to All Files in Notepad Save As dialogue)

class UnrealGameInfo extends SimpleGame;
defaultproperties
{
}

You can switch UnrealGameInfo with whatever name you want, but keep in mind that the name of file and name in the code should be identical.

Let UDK know we exist!

If you think that UDK is gonna pass by, notice the newbie folder and make you happy just like that, I gotta bad news for you! We've got to add an entry in config files about the folder for UDK to take it into consideration when compiling code.
Go to \UDKGame\Config. Find DefaultEngine.ini file there and open it with Notepad. Within this file find this line:
[UnrealEd.EditorEngine]
 Depending on type of your installation there might be one or couple of lines after this one before some blank space starts. So add the following line to the end of the block:
+EditPackages=UnrealGame
Where UnrealGame is name of the folder we created for our classes. Save the file. Now UDK will compile all the code inside this folder, will keep an eye on it and notice changes!

Building!

Depending on IDE, you might not need to go through this step, but I prefer to do this no matter what. Create a shortcut on your desctop to either to \Binaries\Win32\UDK.exe or to \Binaries\Win64\UDK.exe depending on your system. There is no actual difference as far as I'm concerned. (If you don't know which system you're running, just go with 32)
Now go to Properties of the shortcut and add word make to the end of Target line. Like this:
Click OK and double-click the icon! Let's see what happens! If what you see is this (look for  line UnrealGame - Release):
 
Then congratulations! You made it! 
If not, you're probably screwed and gonna have to find what you did wrong! :( Comment here and I'll try to help you out.


Let's make our lives easier!

This step will make the development-testing process much easier, thus faster and more productive! I learned the "trick" from Unreal Development Kit Game Programming with UnrealScript: Beginner's Guide book which I strongly recommend!
Fist we need a scene! If you know what scene you want and are not feeling lazy to make it now, create at least simple version of it in the editor. Otherwise just open editor and save the default scene as UnrealScene in UDKGame\Content\Maps. DO NOT save maps outside this folder.

Open our beloved Windows Notepad! Put the following line in it:

C:\UDK\Binaries\Win32\UDK.exe UnrealScene?GoalScore=0?TimeLimit=0?Game=UnrealGame.UnrealGameInfo -simmobileinput -log
Where  C:\UDK\Binaries\Win32\UDK.exe is path to UDK.exe on your computer. Feel free to change Win32 to Win64 if you're running 64 bit system.

UnrealScene is name of the scene.
UnrealGame name of the folder we created in Development/Src.
UnrealGameInfo is name of the class we created within the folder.
-simmobileinput stands for touch input simmulation. If your target platform is not iOS, remove this. 



Save this as .bat file and call it something like Run_UnrealGame.bat. (don't forget to switch Save As Type to All Files in Notepad Save As dialogue)

Double-click the Run_UnrealGame.bat file! It should start UDK game within the level we choose, using the GameInfo class we wrote!
QUICK TIP: If your computer is as slow as mine, the default resolution UDK runs the game with might be to big for you. Also you simply might want to change the resolution to fit the target platform. To do so open console either by pressing Tab button or "`" button which is the one before number "1" key on the keyboard. Write setres widhtXheight and press Enter. For example for iPhone 3GS screen resolution you would do "setres 480x360" command. Once you close the window, it will always start in the resolution unless you change it.
You're good to go now! 
Edit the class we created, add new classes, build them using the shortcut and run the game using the bat file! 

No comments:

Post a Comment