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'CastleAudi开发者_StackOverflowo.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?
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.
What function are you using to play the sound?
PlaySound will create an AudioComponent on the fly so you shouldn't need to have a component in the defaultproperties section.
var config SoundCue MonsterNoiseSoundCue;
Then when your action happens:
function OnMonsterAction()
{
PlaySound(MonsterNoiseSoundCue);
}
Potential option are dynamic components 'Dynamically created components
To dynamically create an instance of a component, use the UnrealScript new operator and call the actor's AttachComponent method to attach the new component to the actor.'
simulated event PostBeginPlay()
{
local AudioComponent AudioComponent;
Super.PostBeginPlay();
AudioComponent = new(self) class'AudioComponent';
AudioComponent.SoundCue = Cue;//var(audio) SoundCue Cue
AudioComponent.bAutoPlay=true; // !!!
AttachComponent(AudioComponent); // Attach copm. to actor's copm. array
// .....
}
To detach and free the component which you attached earlier, use the actor's DetachComponent method.
http://wiki.beyondunreal.com/UE3:AudioComponent_(UDK)
精彩评论