Does anyone know why I’m getting this error on line 14 when I’m creating a USphereComponent? I’m doing the exact same thing on line 19 but it doesn’t cause the same error.
Thanks
Does anyone know why I’m getting this error on line 14 when I’m creating a USphereComponent? I’m doing the exact same thing on line 19 but it doesn’t cause the same error.
Thanks
That’s because you have a forward declaration in line 11 of the header file as hinted by the compiler error message. It basically tells the compiler that a class/struct with the given name exists somewhere in the code but it won’t make the entire definition of the class available at that point. This is typically sufficient in header files if you don’t access anything that requires the compiler to know the actual declaration of the class (e.g. members, base class, size, etc.) it won’t complain. However somewhere within the call to CreateDefaultSubobject
the object being created is converted from UObject *
to USphereComponent *
. But since the compiler doesn’t now that the forward declared class actually derives from UObject
it throws the error. The fix is to add the missing #include "Components/SphereComponent.h"
to your cpp file only to provide the full declaration for the compiler. Do not add it to the header file though or you’ll lose all the benefits of the forward declaration.
Heya rhduke,
The “use of undefined type” is a clue here… just chuck the include for USphereComponent into your .cpp file and you should be sweet (fingers crossed)
#include “Components/SphereComponent.h”
UStaticMeshComponent is already included in the AActor class, which is why you aren’t getting any complaints there.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.