Starting into Unrealscript isn’t so bad if you’re familiar with a programming language like Java or C++. However, if you’ve mostly been working with 3d animation tools and have never been involved with the programming side of things but want to get into Unrealscript so you can make your own games you might not know where to get started. This is basically where I found myself quite a few years ago. However, I’ve always had a latent interest in programming in general. So along the way I’ve learned how to program in Mel, or Maya Embedded Language, ActionScript, Javascript, and even C/C++. However, I’ve never forgotten how hard things were to learn when I first got started.
Without hesitation I wanted to learn Unrealscript, It wasn’t long before I decided that this was one of the most enjoyable developement environments because what you write can be instantly turned into something you can play with. Here is an example of a script that lets you put the Meatcube form the previous tutorial into a level as a GamePawn. There’s a significant difference between adding the Meatcube to the scene as a placed SkeletalMeshActor where you have to open the actors properties and set them vs. placing a new MeatCubePawn to the scene as a new class object you wrote yourself.
class MeatPawn extends GamePawn placeable; defaultproperties { Begin Object class=SkeletalMeshComponent name=SkeletalMeshComponent0 SkeletalMesh=SkeletalMesh'MeatPackage.MeatCube' End Object Components.Add(SkeletalMeshComponent0) }
Copy that and save it as MeatPawn.uc
There’s a few basic things happening in those few lines of Unrealscript, none of which is all that complex. The first important two words are “class MeatPawn” these words tell UDK two things. First class tells UDK that you’re starting a new Object, and the second word tells UDK what you’re calling the new object. These objects need to match the files name, so that’s why MeatPawn’s class is named MeatPawn.uc, I hope you’re following so far…
In the programming world “objects” are self contained chunks of data that can sit in memory. Objects can be given things to do, or they can just hold onto data. At this point, it’s important to learn about the word “inheritance” as far as programming is concerned it has nothing to do with getting money from a dead relative. However, it has everything to do with getting a copy of properties from another object and using them for yourself.
Next we have the word extends and GamePawn. The word “extends” which means to inherit the properties from, in this case “GamePawn” so the MeatPawn is an extension of GamePawn. Programmers are a lazy bunch, you could just copy all of the text in GamePawn and paste them into your MeatPawn and leave out “extends GamePawn”, and that would accomplish the same thing.
There’s a problem with this of course. GamePawn extends Pawn, which extends Actor, which extends Object. There might be a few other extends in there as well, but needless to say you’d have to start at the distant end of the extending Object and do a lot of needless copy/pasting. So to save ourselves a lot of time we’ll simply “extend” another object so we can use it’s properties.
Now that we’ve told UDK what we’re making and what it’s inheriting from, we’re going to tell it what we want to do with it. In this case we’re going to place it in a level, so we’re going to add the keyword “Placeable” at the end. Keywords are a bunch of words that UDK thinks are special. There are a lot of keywords, so you’re going to need to learn a bunch of them to get to know UDK. We’ll get around to learning those later on.
The last bit on that first line is the semicolon ” ; ” this is like a period at the end of a sentence. This tells the UDK compiler that it’s done with reading a line and needs to start with a new set of commands. Without the semicolon the compiler will remind you that something is broken and it will leave it to you to figure out where you want to fix things.
Next we have “defaultproperties” it’s all one word. and it’s a pretty unique word to Unrealscript. This is a nice way to tell the editor how to handle the new object inside of the game. Then we have a “curly brace” { these are used to group your programs into complete thoughts, or a collection of sentences. } If you think of a semicolon as a period at the end of a sentence. Then a group of sentences is grouped into a paragraph framed with a pair of curly braces.
In this case we’ve got an “object” which begins and ends inside of the curly braces. This stuff is quite unique to Unrealscript. And it’s a bit like “class MeatCube” but in this case we’re saying “Begin Object” and then we’re telling UDK what sort of object we’re beginning by saying “class=SkeletalMeshComponent” then we’re calling our new object “name=SkeletalMeshComponent0″ of course we could have named it anything. For instance we could have said “name=LargeCubeOfMeat” but programmers are particular to “style” and that usually means boring naming conventions.
We’ll use the name in a bit after we give it some reason to be. In this case we’re going to give SkeletalMeshComponent0 a skeletal mesh by saying SkeletalMesh=SkeletalMesh’MeatPackage.MeatCube’ this is how we assign the class a mesh from a package. You can download the MeatPackage.upk and test this out yourself. MeatPackage.MeatCube is actually a path to the object. This works out a lot like a windows directory like UDK/Binaries/Win32/UDK.exe but rather than a / we’re using a . not too hard to understand I hope.
Then we say “end Object” to tell the compiler we’re done assigning properties to the object. Then finally we use “Components.Add(SkeletalMeshComponent0)” to tell the compiler that we want this component to be added to the scene when the object is placed in the level. Phew!! that was a lot to read, and hope you were able to follow along. But we’re not done yet! if you place this code as is in the scene it wont act like a meatcube! So how do we figure that out?
Here’s a cool trick! From the meatcube tutorial we had to make some changes in the placed version of the meatcube to turn on the softbody simulation in the editor.
This has a few check boxes we need to tell our object it also needs to turn on. If you followed the previous tutorial you can open the meatcube’s properties and go to the attribute editor and click the wrench icon.
So now turn on the “Show Only Modified Properties” in the list, and then ” Copy To Clipboard” Then go back to your text editor and paste what you just collected. In my case I got all this:
Begin Object Class=SkeletalMeshActor Name=SkeletalMeshActor_0 Begin Object Class=SkeletalMeshComponent Name=SkeletalMeshComponent0 ObjName=SkeletalMeshComponent_18 Archetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshActor:SkeletalMeshComponent0' Begin Object Class=AnimNodeSequence Name=AnimNodeSequence_39 Archetype=AnimNodeSequence'Engine.Default__SkeletalMeshActor:AnimNodeSeq0' Name="AnimNodeSequence_39" ObjectArchetype=AnimNodeSequence'Engine.Default__SkeletalMeshActor:AnimNodeSeq0' End Object SkeletalMesh=SkeletalMesh'MeatPackage.Meatcube' Animations=AnimNodeSequence'AnimNodeSequence_39' bRecentlyRendered=True bEnableSoftBodySimulation=True bSoftBodyAwakeOnStartup=True SoftBodyRBCollideWithChannels=(Default=True) ReplacementPrimitive=None RBChannel=RBCC_Default LightingChannels=(bInitialized=True,Dynamic=True) Name="SkeletalMeshComponent_18" ObjectArchetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshActor:SkeletalMeshComponent0' End Object Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment ObjName=DynamicLightEnvironmentComponent_0 Archetype=DynamicLightEnvironmentComponent'Engine.Default__SkeletalMeshActor:MyLightEnvironment' Name="DynamicLightEnvironmentComponent_0" ObjectArchetype=DynamicLightEnvironmentComponent'Engine.Default__SkeletalMeshActor:MyLightEnvironment' End Object Begin Object Class=AudioComponent Name=FaceAudioComponent ObjName=AudioComponent_0 Archetype=AudioComponent'Engine.Default__SkeletalMeshActor:FaceAudioComponent' Name="AudioComponent_0" ObjectArchetype=AudioComponent'Engine.Default__SkeletalMeshActor:FaceAudioComponent' End Object SkeletalMeshComponent=SkeletalMeshComponent'testRoom.TheWorld:PersistentLevel.SkeletalMeshActor_0.SkeletalMeshComponent_18' Components(1)=SkeletalMeshComponent'testRoom.TheWorld:PersistentLevel.SkeletalMeshActor_0.SkeletalMeshComponent_18' Location=(X=133.255157,Y=139.067719,Z=20.100000) Tag="SkeletalMeshActor" CollisionComponent=SkeletalMeshComponent'testRoom.TheWorld:PersistentLevel.SkeletalMeshActor_0.SkeletalMeshComponent_18' Name="SkeletalMeshActor_0" ObjectArchetype=SkeletalMeshActor'Engine.Default__SkeletalMeshActor' End Object
Holy cow, thats a lot! However we’re only interested in the three lines
bEnableSoftBodySimulation=True
bSoftBodyAwakeOnStartup=True
SoftBodyRBCollideWithChannels=(Default=True)
Now we’re going to add this to the object so that the new version of our class will look like
class BlobPawn extends GamePawn placeable; defaultproperties { Begin Object class=SkeletalMeshComponent name=SkeletalMeshComponent0 SkeletalMesh=SkeletalMesh'MeatPackage.MeatCube' bEnableSoftBodySimulation=True bSoftBodyAwakeOnStartup=True SoftBodyRBCollideWithChannels=(Default=True) End Object Components.Add(SkeletalMeshComponent0) }
This will now act like the meatcube you placed in the scene before, but how do you place this thing in the scene?
If you go into your ActorClasses tab in the content browser you can find your MeatPawn class under Pawn->GamePawn->MeatPawn This is also the same place where you can get other nifty actors like cameras and lights. This is a pretty cool way to create objects, rather than being so mundane as to having to put objects into the scene as a regular mesh you can add them as actors. Later on we’ll be able to give these actors behaviors because they’re being created by script rather than you having to place them into the scene by hand.
Happy modding!
Copy that and save it as MeatPawn.uc
Where save ???
it needs compile or sompting ???
please help
ah yes, simply use any regular text editor. Paste the contents of the *.uc file into something like notepad.exe and from there save the file as MeatPawn.uc in Development/Src/UTGame/Classes/MeatPawn.uc after that when you run the editor again it will ask if you want to recompile your scripts. Say yes and it will build all your scripts again.
Just make sure that you’re not already running the game or editor and the files in UTGame\Script are not write protected.
I can make a “getting started” tutorial if you like
I can make a “getting started” tutorial if you like
Yes yes yes please.
http://bit.ly/1iAhzK Here’s the link to “Starting from Scratch” Hope this helps you out.