Link error when creating a component inheriting from USphereComponent

Hello,

I wanted to create a new C++ class inheriting from SphereComponent.

First problem : in the editor, in the dialog which is opened after I choose File > Add Code to project, the SphereComponent class is not visible. I decided to choosed the StaticMeshComponent to at least have the basic includes, and changed the files accordingly to inherit from USphereComponent.

The problem I have is that when I build, I have linking errors :

29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UShapeComponent::GetUsedMaterials(class TArray<class UMaterialInterface *,class FDefaultAllocator> &)const " (?GetUsedMaterials@UShapeComponent@@UEBAXAEAV?$TArray@PEAVUMaterialInterface@@VFDefaultAllocator@@@@@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual class UBodySetup * __cdecl UShapeComponent::GetBodySetup(void)" (?GetBodySetup@UShapeComponent@@UEAAPEAVUBodySetup@@XZ)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UShapeComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UShapeComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual class FPrimitiveSceneProxy * __cdecl USphereComponent::CreateSceneProxy(void)" (?CreateSceneProxy@USphereComponent@@UEAAPEAVFPrimitiveSceneProxy@@XZ)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl USphereComponent::IsZeroExtent(void)const " (?IsZeroExtent@USphereComponent@@UEBA_NXZ)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual struct FCollisionShape __cdecl USphereComponent::GetCollisionShape(float)const " (?GetCollisionShape@USphereComponent@@UEBA?AUFCollisionShape@@M@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl USphereComponent::AreSymmetricRotations(class FQuat const &,class FQuat const &,class FVector const &)const " (?AreSymmetricRotations@USphereComponent@@UEBA_NAEBVFQuat@@0AEBVFVector@@@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual struct FBoxSphereBounds __cdecl USphereComponent::CalcBounds(class FTransform const &)const " (?CalcBounds@USphereComponent@@UEBA?AUFBoxSphereBounds@@AEBVFTransform@@@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl USphereComponent::CalcBoundingCylinder(float &,float &)const " (?CalcBoundingCylinder@USphereComponent@@UEBAXAEAM0@Z)
29>BBHoopSphereComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl USphereComponent::UpdateBodySetup(void)" (?UpdateBodySetup@USphereComponent@@UEAAXXZ)

Any idea of what is going wrong?

Thanks

Here is the trick:

  1. Remove the keyword MinimalApi from the UCLASS macro above UShapeComponent and USphereComponent
  2. Put ENGINE_API between the keyword class and the UShapeComponent and USphereComponent name
  3. Remove all ENGINE_API from the functions in the headers of UShapeComponent and USphereComponent

Here are what the declarations of UShapeComponent and USphereComponent should now look like:

UCLASS(HeaderGroup=Component, ClassGroup=Shapes, editinlinenew, hidecategories=(Object,LOD,Lighting,TextureStreaming), meta=(BlueprintSpawnableComponent))
class ENGINE_API USphereComponent : public UShapeComponent
{
    // ...
};

UCLASS(abstract, HeaderGroup=Component, hidecategories=(Object,LOD,Lighting,TextureStreaming,Activation,"Components|Activation"), editinlinenew, meta=(BlueprintSpawnableComponent), showcategories=(Mobility))
class ENGINE_API UShapeComponent : public UPrimitiveComponent
{
    // ...
};

Just to add to this, UBoxComponent, USphereComponent and UCapsuleComponent are all marked as ENGINE_API in 4.1, so this problem will be resolved.