I figured out what the problem was. Even though I was assigning a sound to the component in the editor, it wasn’t assigning it to the sound. I also forgot to change bAutoActivate to false. So this little exercise worked the way I expected.
Code in cpp file should be this. For anyone search later on how to attach audiocomponents with sound in code.
ACodeFirstPersonCharacter::ACodeFirstPersonCharacter()
{
static ConstructorHelpers::FObjectFinder<USoundBase> Sound(TEXT("SoundWave'/Game/FirstPerson/Audio/dungeonwav.dungeonwav'"));
MySound = Sound.Object;
MyAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("AudioTest"));
MyAudioComponent->AttachParent = GetMesh1P();
MyAudioComponent->SetSound(MySound);
MyAudioComponent->bAutoActivate = false;
}