Search code examples
unreal-development-kitunrealscript

In Unrealscript how do I have a config value for a resource in a class set a property of a component?


I have a sound cue that I want played whenever the player does a specific action. I've got it playing fine and everything but I want to make the resource that is used come from a configuration file instead of being hard coded.

So I added a property to my class called MonsterNoiseSoundCue as follows:

var config SoundCue MonsterNoiseSoundCue;

Then in the DefaultProperties section I added the following to the object I create which then then added to the components collection of my pawn.

Begin Object Class=AudioComponent Name=MonsterActivatedSound1
         bAutoPlay=false
         SoundCue=MonsterNoiseSoundCue// This variable is a configured value.   SoundCue'CastleAudio.UI.UI_StopTouchToMove_Cue'
    End Object
    Components.Add(MonsterActivatedSound1);
    MonsterActivatedSound = MonsterActivatedSound1;

For some reason it doesn't build saying "Not allowed to use 'config' with object variable." Does anyone know of another way to approach this?


Solution

  • That "Not allowed to use 'config' with object variable." message was a change in UnrealEngine 3.

    I cannot test right now and I'm a UT2004 scripter, but I would try this:

    var SoundCue MonsterNoiseSoundCue;
    var config string MonsterNoiseSoundCueName;
    

    In your PreBeginPlay function (or similar), use this to get the cue:

    MonsterNoiseSoundCue = SoundCue(DynamicLoadObject(MonsterNoiseSoundCueName, class'SoundCue'));
    

    You should get a warning in the log if the sound cue doesn't exist.