Design 1, Design 3 (Computer and Video Games)
Unit 8 - 26th, 28th November 2002

Stochastic Music in Unreal

This is how you can create a room with different sounds coming from different spatial locations triggered randomly. The setup works in such a way that a sequence of sounds will be played at randomly chosen times as long as the player pawn activates the trigger. Once the trigger is no longer activated there will be no more sequence of sounds.

There is a device called the DynamicAmbientSound which can be found in the "Keypoint" Actor Classes. This class triggers randomly selected sounds as well. It does however just play the sound files from one spatial location which is the location the keypoint is added to.

If you want to have sound sources spread through the whole space - resembling multiple loudspeakers in a room - you'd rather have to apply a technique using the "Stochastic Trigger".

Even though the stochastic trigger is called a trigger, it is a device which needs a trigger to be activated. Watch the screenshot to the right to see what you have to add to your room:

1. A "Trigger" in the lower corner.
2. A "Stochastic Trigger", looking like the head of a dinosaur.
3. Two or more than two "Special Events". These are the boxes on the left and on the right of the red room. They look like triggers with an exclamation mark printed on them.

First you have to connect the "Trigger" to the "Stochastic Trigger". Do so by setting the "Event" parameter in the Event properties of the trigger to "Randomgenerator". Then set the "Tag" parameter of the stochastic trigger to "Randomgeneratro" as well. A red line between trigger and stochastic trigger should be visible on the 2D-views now.

Next thing you have got to do, is to adjust the properties of the stochastic trigger.

You can see on the properties window on the right that the properties for "Events", "Object" and "Stochastic Trigger" are the ones one has to take care of.

The "Initial State of the object should be set to "TriggeredActive", which means that it is only activated when triggered. Set the Events[0], Events[1], Events[2], ... Events[n-1] to a name which corresponds to the "Tag" parameter's value of the corresponding special event.

Change the "TriggerProbability" from 0.0 to a value in between 0.000001 and 1.000000. "MaxReCheckTime" and "MinReCheckTime" define the minimum delay for the randomgenerator to generate a new event and the maximum delay to do so. If you set "MinReCheckTime" to 10, this means that there can be no sound following the sound presently played earlier than 10 seconds after the start time of the present sound. It does not mean that 10 seconds after the first sound the second has to be played, because the second one could be started anytime in between 10 seconds from the start of the first one and "MaxReCheckTime" from the start of the first one. Also if the randomgenerator does not produce an event there will be another "MinReCheckTime" at least to wait for the next sound.

You can download a sample .unr file to try this thing out.
Click here to download the Unreal level (zipped file 2.4 kB). You need to have Basics.utx (zipped file 180 kB) in your textures folder and have the "Basics" package defined as an EditPackage in order to play the example file.