Unreal Coding FAQ
Got a question that isn't covered here? Add it to the list (at its appropriate place) and leave the answer out. Somebody else will fill it in.
Note: Only frequently asked questions, please. For anything else there are forums like [BUF Coding].
See also Compiler Errors.
Basics
- I can't modify .uc files in my Text Editor. I get a message "This Document is Read Only"
- Right click the file in Windows Explorer, then hit properties and uncheck the "read only" box. Epic seems to have had the foresight to make all the files in the UnrealScript Source distribution for UT2003 read-only, so if people are going to copy and paste a class to use as a template, they may run into this problem. Remember not to recompile the original Epic classes: Do Not Alter Default Packages.
- I get an error when trying to compile Engine.u (or one of the other .u files that comes with the game)
- You shouldn't change any of these. In UnrealScript, as in most Object Oriented programming (and unlike Quake? or HalfLife coding), you never change something that exists. You really don't want to change the code that comes with the game, since that will change all versions of the game and all mods, and most people don't want that, to say the least. Instead, when you want to change something in a class, you create your own version of the class, then get the game to use your version instead of the built in version. How you get it to use the new version depends pretty heavily on which class it is. See Object Oriented Programming Overview.
- It doesn't work.
- Make sure your package actually compiled without any compiler errors and is used in the game. (Simply subclassing stuff doesn't make the game use your new class! You have to explicitly add it in a map or through a mutator or gametype.)
See Debugging Techniques. - I can't see my gametype/mutator on the list in-game.
- Be sure you have properly setup the INT file, otherwise the Unreal Engine is blissfully unaware of your new code unless it's in a map.
- I am trying to get a bot to follow the player in a single player mod, how can I do this?
- You ask in a dedicated Coding forum because this question is not a frequently asked and as simple as we would like the questions to be for this page.
The UnrealScript Language
Things that are built in to the language, not that come in any package.
- Expands vs. Extends – What's the difference?
- UnrealScript originally used "expands", but long ago switched to "extends", the keyword used in Java. The Unreal Tournament compiler supports both and treats them the same. So, always use extends when you have a choice. In UT2003, "expands" isn't supported at all anymore. Always use "extends" there.
- Rotators... what the hell are they?
- All is explained in technicolor on the Rotator page.
- Function Pointers
- See Delegate.
- Unknown Code Token 04
- When you create native functions in your UnrealScript class, you also have to define it in C++. For each UnrealScript argument, you need a P_ macro in C++. If you forget to put one of the P_ macros in your C++ code, you'll get the "Unknown code token 04" error.
- How to save information between levels on the user's hard drive
- See Config vars and .ini files.
- How can I tell if my class exists in the game?
- Bring up the Console and type editactor class=[name of your class]. You must be running UT2003 in windowed mode to see the results. You can also use the Log("something happened") in your class and later find it in the System/UT2003.log. If your class is not available, you will get a Target Not Found response in the console.
- How can I get a reference to the object a piece of code belongs to?
- Use the Self keyword. Also see Special UnrealScript Keywords for details.
- How can I call an ancestor class' version of a function or a non-state function from within a state?
- This is done via the Super and Global keywords respectively. Again, see Special UnrealScript Keywords for more details.
- Even if I need to call the super of a super? Super.super? Super duper? The parent of a parent?
- Yes, super can access up the parent chain with the right format, again see Special UnrealScript Keywords for more details.
- Can someone explain this sort of syntax? Sound'WeaponSounds.LinkGun.SwitchToLinkGun'. Is it related to the class<blahblah> style syntax? I've also seen class'blahblah', is that the same?
- It is related, sort of. It's more like the class'Somepackage.Someclass' syntax. The class syntax refers to classes though, while this refers to an object, usually a resource like a texture or a sound or something like that. See Peppers And Pepper Grinders.
Replication
Replication is the name of UnrealScript's networking interface. It supports both remote procedure calls and the synchronization of variables across machines.
- What should I read to understand replication?
- In this order:
- [Unreal Networking Architecture] at unreal.epicgames.com
- Mod Authoring/A Few Things To Watch Out For (scroll down to Decrypting Replication)
- [Replication De-Obfuscation]
- Replication, replication condition, replicated function, Role, simulated function
Input
Keybindings, mouse movements, exec functions, etc.
- How do I bind keys?
- See Binding Keys.
HUD (Heads-Up Display)
The icons displaying health, etc.
- What are all those arguments to DrawTile()?
- See Canvas, the class which defines that function.
- How does transparency work in the HUD?
- See Color Blending.
Physics
- If I want to create a ballistics system for my mod, how do I start making it? Are the UT2004 physics adequate for the task?
Other
mrbond113: Since unreal.epicgames.com is basically shutting down their hosting of older (i.e., Unreal, UT) coding resources, I think BU should host the [Unreal Networking Architecture] info. Not sure where it would go, but I think for the good of the newer coding community, it should happen.
Foxpaw: The network architecture described in that document is the same one currently in use - so there's a good chance it will stick around.
- I know it is possible to create bullet holes on walls using dynamic projectors. Can I do the same on my player models?