# How to disable auto activation of the UAudioComponent from C++

**URL:** <https://forums.unrealengine.com/t/how-to-disable-auto-activation-of-the-uaudiocomponent-from-c/324277>\
**Category:** Audio\
**Tags:** activate, unreal-engine, CPP, question\
**Created:** [July 6, 2015, 5:35pm UTC](https://forums.unrealengine.com/t/how-to-disable-auto-activation-of-the-uaudiocomponent-from-c/324277 "2015-07-06T17:35:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KnofLer\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KnofLer\_1](https://forums.unrealengine.com/u/KnofLer_1)\
**Post date:** [July 6, 2015, 5:35pm UTC](https://forums.unrealengine.com/t/how-to-disable-auto-activation-of-the-uaudiocomponent-from-c/324277/1 "2015-07-06T17:35:44Z")

</div>

Hi guys. Have a trouble here.  
Needed to create dynamic massive of UAudioComponent pointers, so can’t declare it as a UPROPERTY.  
How can I stop the auto activetion and, though stop auto playing my sounds?

Here is like my massive is declared:  
UAudioComponent \*\*SoundComponent;

---

<div class="post-metadata">

**Author:** ![Shmoopy1701](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shmoopy1701/32/1194536_2.png) [@Shmoopy1701](https://forums.unrealengine.com/u/Shmoopy1701)\
**Post date:** [December 11, 2015, 3:15pm UTC](https://forums.unrealengine.com/t/how-to-disable-auto-activation-of-the-uaudiocomponent-from-c/324277/2 "2015-12-11T15:15:04Z")

</div>

This is old but shows up in Google searches, so here is the answer. This code attaches any number of sounds to an Actor and plays/stops them with by passing in the name.

```
/**
* List of sound cues played by this actor.
*/
TMap<FName, UAudioComponent*> _soundCues;

/**
* Add a sound component to actor.
* Actor manages sound cues for all components in a map.
*/
void AInteractiveActor::AddSoundComponent(FName soundName, const char* cueAssetNameAndPath)
{
	UAudioComponent* newCue = CreateDefaultSubobject<UAudioComponent>(soundName);
	ConstructorHelpers::FObjectFinder<USoundCue> cueAsset(ANSI_TO_TCHAR(cueAssetNameAndPath));
	
	if (cueAsset.Object != NULL)
	{
		newCue->AttachTo(RootComponent);
		newCue->bAutoActivate = false;
		newCue->SetSound(cueAsset.Object);

		_soundCues.Add(soundName, newCue);
	}
	else
	{
		UE_LOG(MCS, Error, TEXT("%s: add sound component failed!"), *GetUniqueName());
	}
}

/**
* Play a sound cue.
*/
void AInteractiveActor::PlaySound(FName cueName)
{
	// find sound in cue list
	UAudioComponent* cue = _soundCues.FindRef(cueName);
	if (cue && !cue->IsPlaying())
	{
		cue->Play();
	}
}

/**
* Stop a sound cue being played.
*/
void AInteractiveActor::StopSound(FName cueName)
{
	// find sound in cue list
	UAudioComponent* cue = _soundCues.FindRef(cueName);
	if (cue && cue->IsPlaying())
	{
		cue->Stop();
	}
}
```

---

<div class="post-metadata">

**Author:** ![Shmoopy1701](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shmoopy1701/32/1194536_2.png) [@Shmoopy1701](https://forums.unrealengine.com/u/Shmoopy1701)\
**Post date:** [December 11, 2015, 3:17pm UTC](https://forums.unrealengine.com/t/how-to-disable-auto-activation-of-the-uaudiocomponent-from-c/324277/3 "2015-12-11T15:17:16Z")

</div>

^^ Use the above code like this:

```
// add audio component in your Actor constructor
AddSoundComponent("alarm", "/Game/Audio/Test/alert_Cue.alert_Cue");

// play or stop sounds at any time in game like this
PlaySound("alarm");
StopSound("alarm");
```
