Legacy:UT3 Hello World

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to navigation Jump to search

Getting Ready

Assuming you have read the first UT3 lesson on UT3 Whats What, You should be ready to make your first mod.

The simplest of mods is the "Hello World" mutator.

Go to "C:\Users\<username>\Documents\My Games\Unreal Tournament 3\UTGame\Src" (or equivelent) and create a new folder. The Folder name will be the package name for your mod. For this tutorial, name the folder "HelloWorld". In this folder, create another folder called classes.

  The classes folder is where all your source files will go.

Open up "..\UTGame\Config\UTEditor.ini" and find the [ModPackages] section, and add to it a line that reads "ModPackages=HelloWorld"

Save and close the file.

Create a file in this folder and name it "HW_Mutator.uc" and open it for editing.

Either open notepad and Save As, or create a new .txt document and rename it, making sure that it has the correct file extension. (By default, windows hides known file extensions. This can be disabled in Tool>Folder Options...>View.)

The Code

<uscript> class HW_Mutator extends UTMutator;

function InitMutator(string Options, out string ErrorMessage) {

    loginternal( "Hello World" );

Super.InitMutator(Options, ErrorMessage); }

</uscript>

Note: the class name must be the same as the file name.

Sandymac: I think you need to run 'UT3 make' before you launch the game to test the mutator.

Now, run UT3 -useunpublished and start a game with your mutator. When the mutator is loaded "Hello World" will be outputted to a log file.

The log file will be in "..\UTGame\Logs\"

Vaptor: i don't think you tried useunpublished cause it keeps crashing with not recognized

Rye: Pretty simple mod. As i am still getting my head around UScript myself, my advice to people new to scripting is you should search and search and search. Dont post on forums the instant you get stuck. Try looking at other pieces of source code and see if you can figure it out. Aside from it being more satisfying, you will also learn UScript faster.

Raven: I have noticed that when you reverse engineer the script using UnrealEd that is does not include any embedded objects. This is particularly important for UT3, as that all components are now exactly that. An example of this is the StaticMeshActor class:

<uscript> class StaticMeshActor extends StaticMeshActorBase native placeable;

var() const editconst StaticMeshComponent StaticMeshComponent;

event PreBeginPlay() {}

defaultproperties {

  StaticMeshComponent=StaticMeshComponent0
  Components(0)=StaticMeshComponent0
  BlockRigidBody=True
  CollisionComponent=StaticMeshComponent0
  CollisionType=COLLIDE_BlockAll
  Name="Default__StaticMeshActor"
  ObjectArchetype=StaticMeshActorBase'Engine.Default__StaticMeshActorBase'

} </uscript>

The reference to StaticMeshComponent0 should be included in the default properties, but is not extracted during reverse engineering. It should have something like:

<uscript> Begin Object Class=StaticMeshComponent Name=StaticMeshComponent0

  bAllowApproximateOcclusion=TRUE
  bCastDynamicShadow=FALSE
  bForceDirectLightMap=TRUE

End Object </uscript>

Raven: Probably should also mention that it is a good idea to download the scripts from UDN: http://udn.epicgames.com/Three/UT3ModHome.html

EricBlade: I am not having Raven's problem with the exported script not having the objects, although I did definitely have that problem with older Unreal games. I would like to note that in Object.uc, directly above the LogInternal() function, it says that you should never call that function directly, rather use the log() macro .. Apparently this is done by doing `log("message"); .. and as an aside, anyone know what the ` does, and is this 'macro' functionality available to us as coders somewhere? ...

EricBlade: More related to the topic at hand, after doing UT3 Make, I do UT3 -useunpublished, and it starts to start, but then gives me a VC++ crash window, and my CPU usage skyrockets to 100% and stays there until i managed to click OK to get rid of the window, and UT3 closes. The log dosen't look especially useful here, either. In fact, running "ut3" with any arguments except "make" now gives me a VC++ crash window. ugh.

Raven: I had that problem happen as well. For me it seemed to be a directX conflict, went away when I rebooted the computer. You should also use the -log command, as this will give you a chance to see the log messages in real time.