# Audio Component Play not working

**URL:** <https://forums.unrealengine.com/t/audio-component-play-not-working/620018>\
**Category:** C++\
**Tags:** unreal-engine, UE4-26, UE4, question, CPP\
**Created:** [August 2, 2022, 6:50pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018 "2022-08-02T18:50:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quanthis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Quanthis](https://forums.unrealengine.com/u/Quanthis)\
**Post date:** [August 2, 2022, 6:50pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/1 "2022-08-02T18:50:51Z")

</div>

Sorry for a bit clickbait title. The problem for me is in fact Play() not playing sound attached to UAudioComponent. However I’d guess I just do something wrong, but can’t figure out what several days already. Does anyone have an idea?

Here is how the object is declared in my game instance class header:

```auto
	UPROPERTY(EditDefaultsOnly)
		UAudioComponent* idleVillage;

```

Then later it is created in the constructor:

```auto
	idleVillage = CreateDefaultSubobject<UAudioComponent>(TEXT("IdleVillage"));

```

In Blueprint class deriving from my game instance class I then added the sound

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/d/a2db3b744139c2e426595be8c31966a400b4e1d9.png)  
And then finally I call play somewhere in my code

```auto
	UE_LOG(LogTemp, Log, TEXT("ChangeMusicState call received"));
	currentMusicState = newState;

	idleVillage->Activate();
	idleVillage->Play(0.f);	

```

By logs I can see that the method is called, but the music is not playing. I tried playing it via UGameplayStatics, like this

```auto
	UGameplayStatics::PlaySound2D(this, idleVillage->Sound);

```

And then it does play, but that’s rather bad of a workaround since I need to be able to stop the sound.  
So once again, does anyone have any idea what am I doing wrong? (If any additional informations are required, just ask please, I will proivide them)

---

<div class="post-metadata">

**Author:** ![SolidSk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidsk/32/1194513_2.png) [@SolidSk](https://forums.unrealengine.com/u/SolidSk)\
**Post date:** [August 2, 2022, 10:53pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/2 "2022-08-02T22:53:42Z")

</div>

In your constructor:

```auto
idleVillage = CreateDefaultSubobject<UAudioComponent>(TEXT("IdleVillage"));
idleVillage->SetupAttachment( **RootComponent** );

```

Then:

```auto
UE_LOG(LogTemp, Log, TEXT("ChangeMusicState call received"));
currentMusicState = newState;

// idleVillage->Activate(); Not sure if you need this
idleVillage->SetSound(Sound);
idleVillage->Play(0.f);	

```

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 6:02am UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/3 "2022-08-03T06:02:56Z")

</div>

The sound you are trying to play could be optimized away, this happens when the volume is 0 or when you are far away I believe. On the sound asset editor configure it to play virtualized when silent.

\*Edit You can also do that in c++.

```auto
// USoundBase* Sound
Sound->VirtualizationMode = EVirtualizationMode::PlayWhenSilent;

```

---

<div class="post-metadata">

**Author:** ![Quanthis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Quanthis](https://forums.unrealengine.com/u/Quanthis)\
**Post date:** [August 3, 2022, 5:44pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/4 "2022-08-03T17:44:45Z")

</div>

Thanks for reply!

This sound is already set in deriving class as visible in screen in OP, but I will upload that again:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/6/f86d7a63e2ed45d6ece88dded9c785469cf31044.png)

Also I don’t think Game Instance types have Root Component since they are not scene components, hmm

---

<div class="post-metadata">

**Author:** ![Quanthis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Quanthis](https://forums.unrealengine.com/u/Quanthis)\
**Post date:** [August 3, 2022, 5:45pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/5 "2022-08-03T17:45:11Z")

</div>

Thanks for the reply!  
I tried to set this both in Blueprints and CPP, but unfortuantelly no effect ☹

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 9:29pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/6 "2022-08-03T21:29:54Z")

</div>

> [@Quanthis](#):
>
> since they are not scene components

Good point, unsure about this. I made a music player once as a GameInstanceSubsystem but I just realized I use CreateSound2D to play the audio.

```auto
UObject* WorldContext = GetOuter()->GetWorld();
Sound->VirtualizationMode = EVirtualizationMode::PlayWhenSilent;

AudioComponent = UGameplayStatics::CreateSound2D(WorldContext, Sound, 1.0f, 1.0f, 0.0f, nullptr, true, false);

```

I don’t use CreateDefaultSubobject or SetupAttachment there, I simply have an array of structs and each struct holds an UAudioComponent pointer among some other data.

---

<div class="post-metadata">

**Author:** ![Quanthis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Quanthis](https://forums.unrealengine.com/u/Quanthis)\
**Post date:** [August 6, 2022, 2:10pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/7 "2022-08-06T14:10:01Z")

</div>

Ok I found out what is wrong. It seems components added to GameInstance are kind of ignored, since they require World Context to exist. I tried attaching AudioComponent to a sub-Character class and call Play and everything works. It seems that Game Instance does not support this, sadly.

Once again, thanks for answers!

---

<div class="post-metadata">

**Author:** ![SolidSk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidsk/32/1194513_2.png) [@SolidSk](https://forums.unrealengine.com/u/SolidSk)\
**Post date:** [August 6, 2022, 3:35pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/8 "2022-08-06T15:35:58Z")

</div>

I’m using **AudioComponent** in a **GameInstance** for persistent music, make sure you are calling `UGameplayStatics::CreateSound2D` when a level is loaded ( BeginPlay for example ), not in the constructor.  
I’m using `UGameplayStatics::CreateSound2D` in a function called by BeginPlay when the first level is loaded.

---

<div class="post-metadata">

**Author:** ![Quanthis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Quanthis](https://forums.unrealengine.com/u/Quanthis)\
**Post date:** [August 7, 2022, 12:30pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/9 "2022-08-07T12:30:33Z")

</div>

Game Instance does not have BeginPlay, nor in CPP, nor in Blueprints, nor in docs. I’m sorry, but are you not confusing it with Game Mode?

---

<div class="post-metadata">

**Author:** ![SolidSk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidsk/32/1194513_2.png) [@SolidSk](https://forums.unrealengine.com/u/SolidSk)\
**Post date:** [August 7, 2022, 8:55pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/10 "2022-08-07T20:55:56Z")

</div>

I’m calling **GameInstance** function in a **GameMode** ’s **BeginPlay** ( could be in any Actor ). **GameMode** is per level, **GameInstance** per game.

---

<div class="post-metadata">

**Author:** ![HeyitsSavio](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heyitssavio/32/1185092_2.png) [@HeyitsSavio](https://forums.unrealengine.com/u/HeyitsSavio)\
**Post date:** [June 18, 2026, 11:50pm UTC](https://forums.unrealengine.com/t/audio-component-play-not-working/620018/11 "2026-06-18T23:50:55Z")

</div>

The Persistent Music Plugin is free on fab now for UE 5.0 and up, which will handle all of this automatically for you through an easy to use game instance subsytem

> **[Persistent Music](https://www.fab.com/listings/f59486af-4456-450a-b37f-9856ed0a808f)**
>
> Have you ever wondered why music and sounds stop when unloading and opening a new Level?The Persistent Music Subsystem handles everything you need to have music persist from the moment your game Launches to the second you Quit Game!This is the only...
