Tuesday, October 22, 2013

Custom Footstep Sounds in UDK

Custom Footstep Sounds in UDK

October 22nd, 2013

Getting custom footsteps/jump/landing sounds working in UDK is anything but straight forward. I am going to provide you a complete working solution so that you do not have to struggle with this like I did.

First off, all examples I found on the web were incomplete/incorrect. Maybe it is because I am using a beta version of UDK for the Rift but the examples I found did not work. They got me going in the right direction but they didn't work.

Second, there is some weird code under the hood of UDK. Base classes making references to subclasses (that is a big no-no) and returning hardwired values for things.

I will provide code for this tomorrow.

Sound/Texture work

1. Create a sample sound.
I used quack from this website. It will need turned into 16bit/44100 wav.
(see prior blog entry for how to do this)

2. Import the sound into UDK
(see prior blog entry for how to do this)

3. Create a sound cue for the quack.
> right click in content browser and select 'new sound cue'.
> give the sound cue a name and press ok. This will take you into the sound cue editor.
> leave the editor open and return to the content browser
> select your sound (quack) and return to the sound cue editor
> right click in the sound cue editor and select 'SoundNodeWave: quack'
> connect the sound to the speaker and close the editor

4. Create a physical material to hold the "material name" you will associate with quack
> physical materials are special materials that the physx engine can use. In this case we are going to use it to reference the sound cue of the quack footsteps.
> right click in the content browser and select 'new physical material'
> give the physical material a name. I think the naming convention is ph_{name}. ex:ph_quack_material
> The last property is "Physical Material Property". click the blue arrow to the right and pick "UTPhysicalMaterialProperty".
> In the "Material Type" enter the "quack" for the value. This is the entry we will reference in the unrealscript code.

5. Assign the physical material to your "display material"
> Open the material you want to make noise when you walk on it.
> Expand the "Physical Material" section
> In the content browser select your physical material
> Return to the "physical material" of you texture material and assign the physical material by clicking the green arrow to the right of the "Phys Material" entry.
> close the texture material and you are done with the UDK editor part.

At this point you have a texture with the "quack" physical material associated with it. Now we need to get the unrealscript code in place.

UDK unrealscript prepwork

If you have never coded in unrealscript there is a bit of work involved to get your environment setup. There are a lot of tutorials that cover this topic in detail so I will be brief.

1. I recommend you fire up the UDK log when the editor comes up. It just saves you a lot of digging constantly for log files. In your executable shortcut (on the start button and/or desktop) add -log to the end of the executable target. Like this:
C:\UDK\UDK-2013-03\Binaries\UDKLift.exe editor -log
> You can use the log to look for log entries I have added to the custom code such as this:
> when you watch the log you should see my log entries. If so, you know you are on the right track.

2. You need to add a directory for your custom unrealscript code.
It will code here: C:\UDK\UDK-2013-03\Development\Src\
You will need a name for your project and a classes subdirectory. In the end it will look something like this: C:\UDK\UDK-2013-03\Development\Src\myproject\Classes
> All of your unrealscript custom code will go in that Classes directory

3. We need to let the unreal system know about your custom directory.
> open this is a text editor: UDK\UDKGame\Config\UDKEngine.ini
> In the [UnrealEd.EditorEngine] section add this entry at the bottom:

Adding code to make it work

We need 4 custom scripts/files to make this work

To make this is as simple as possible I have added them to gist:

Save these files in your Classes directory

Here is a brief overview of the 4 files/classes:

CustomGame.uc :
This is a new Game you are creating. It extends UTGame (a must) and overrides the damn SetGameType method. That was the secret sauce that took me days to sort out.

This is a controller for handling activity from the player.

This represents your player and other spawned characters. This forces the system to use your new sound class.

This is where the magic happens. All of the sound customization you need to do is right here. FootstepSounds, JumpingSounds & LandingSounds are arrays that hold possible sound mappings.
> MaterialType = the value you gave "Material Type" in the physical material in the UDK editor.
> This material type is mapped to a sound cue via this array.

You will need to edit CustomGameSoundGroup.uc. This is where you map the physical material so they make a noise. The line of interest is:

You will need to change the project name to match your project.

Compiling the code

The easiest way to compile the code is to let UDK do it for you. Because UDK knows about your code directory (via UDKEngine.ini change you made), it checks to see if anything in it has changed and needs compiled when it starts.

Restart the UDK editor and it will ask you to recompile the unrealscript. Hopefully you won't have any issues. Close that and restart the UDK editor again

Selecting your game

One of the classes you added is CustomGame. This will now be available to pick from within the UDK editor. Select CustomGame for your level in the menu item View:World-Properties

Add a mesh that uses your texture and walk on it. Voila! You have quacking.

Now you can adjust/add more sounds & physical materials and make them work by adjusting the code in CustomGameSoundGroup.

I know this is a lot of stuff and you may run into difficulties. I didn't feel like taking snapshots of all the steps. It was too much work. If you need help just comment on this blog and I'll do my best to help you you.

I have also referenced this tutorial in the UDK forum. You may want to check there too:

No comments:

Post a Comment