Error Creating a UAudioComponent in C++

I have the following code:

UAudioComponent *foo = CreateDefaultSubobject(TEXT(“FUBAR”));

It keeps generating the following errors:

2>C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(83): error C2027: use of undefined type ‘UAudioComponent’

2>C:\Program Files\Epic Games\UE_4.16\Engine\Plugins\Online\OnlineSubsystemUtils\Source\OnlineSubsystemUtils\Public\OnlineSubsystemUtils.h(17): note: see declaration of ‘UAudioComponent’

2>C:\Storage\SSD2\UE4Projects\MicInput\Source\MicInput\MicCharacter.cpp(20): note: see reference to function template instantiation ‘TReturnType *UObject::CreateDefaultSubobject(FName,bool)’ being compiled

2> with

2> [

2> TReturnType=UAudioComponent

2> ]

2>C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(84): error C2440: ‘static_cast’: cannot convert from ‘UObject *’ to ‘UAudioComponent *’

2>C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(84): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Any Suggestions what I am doing wrong?

NIce!

That’s the ticket! Thank you very much!

Looks like you need to include the header in order to use the UAudioComponent type:

#include "Components/AudioComponent.h"

To be added above the generated.h file in the header of the class which is getting the compile error.