Link errors extending CapsuleComponent

I’m trying to add some physics-related functionality to CapsuleComponent. Unfortunately, I’ve run into a few snags with this. I went into the class browser, found CapsuleComponent, right-clicked, and chose “add new C++ class” (wording may be off, but it’s the obvious one). Typed in name of new component, went into MSVC, and tried to build a completely bare new class.

And I get a massive pile of unresolved-external-symbol errors:

Error	1	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)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	2	error LNK2001: unresolved external symbol "public: virtual class UBodySetup * __cdecl UShapeComponent::GetBodySetup(void)" (?GetBodySetup@UShapeComponent@@UEAAPEAVUBodySetup@@XZ)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	3	error LNK2001: unresolved external symbol "public: virtual void __cdecl UCapsuleComponent::Serialize(class FArchive &)" (?Serialize@UCapsuleComponent@@UEAAXAEAVFArchive@@@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	4	error LNK2001: unresolved external symbol "public: virtual void __cdecl UCapsuleComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UCapsuleComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	5	error LNK2001: unresolved external symbol "public: virtual struct FBoxSphereBounds __cdecl UCapsuleComponent::CalcBounds(class FTransform const &)const " (?CalcBounds@UCapsuleComponent@@UEBA?AUFBoxSphereBounds@@AEBVFTransform@@@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	6	error LNK2001: unresolved external symbol "public: virtual void __cdecl UCapsuleComponent::CalcBoundingCylinder(float &,float &)const " (?CalcBoundingCylinder@UCapsuleComponent@@UEBAXAEAM0@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	7	error LNK2001: unresolved external symbol "public: virtual class FPrimitiveSceneProxy * __cdecl UCapsuleComponent::CreateSceneProxy(void)" (?CreateSceneProxy@UCapsuleComponent@@UEAAPEAVFPrimitiveSceneProxy@@XZ)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	8	error LNK2001: unresolved external symbol "public: virtual bool __cdecl UCapsuleComponent::IsZeroExtent(void)const " (?IsZeroExtent@UCapsuleComponent@@UEBA_NXZ)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	9	error LNK2001: unresolved external symbol "public: virtual struct FCollisionShape __cdecl UCapsuleComponent::GetCollisionShape(float)const " (?GetCollisionShape@UCapsuleComponent@@UEBA?AUFCollisionShape@@M@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	10	error LNK2001: unresolved external symbol "public: virtual bool __cdecl UCapsuleComponent::AreSymmetricRotations(class FQuat const &,class FQuat const &,class FVector const &)const " (?AreSymmetricRotations@UCapsuleComponent@@UEBA_NAEBVFQuat@@0AEBVFVector@@@Z)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	11	error LNK2001: unresolved external symbol "public: virtual void __cdecl UCapsuleComponent::UpdateBodySetup(void)" (?UpdateBodySetup@UCapsuleComponent@@UEAAXXZ)	C:\werk\starclock\Intermediate\ProjectFiles\ShipPhysicsComponent.cpp.obj	Starclock
Error	12	error LNK1120: 11 unresolved externals	C:\werk\starclock\Binaries\Win64\UE4Editor-Starclock.dll	Starclock

I’m guessing it’s trying to find the base UCapsuleComponent functions, but being unable to because my dll isn’t being linked properly with whatever defines those functions. It is, however, not clear to me how to fix this. I don’t want to change those functions - I want them to behave exactly like they already do - so somehow, I need for that link to work.

How can I get this to link properly, to make a subclass of CapsuleComponent that is - at least at the moment - identical to CapsuleComponent?

It looks like you are missing a module dependency. In your module in which you want to use UShapeComponent, open the YourModuleName.Build.cs file and add a PrivateDependencyModuleNames dependency to the module that contains the UShapeComponent type. This will allow the linker to find the exported methods. Repeat this for any other types that have unresolved external symbols.

How do I know what module contains the UShapeComponent/UCapsuleComponent types? I can’t find anything in the headers or source files that’s module-related, and the file layout of the UE4 source leads me to believe it’s in Engine, which is already included as a public dependency.

(and I tried adding it as a private dependency also but unsurprisingly that didn’t help)

Wild guessing at things like “Shape” and “Component” and “ShapeComponent” wasn’t fruitful.

I actually don’t think this is a module dependency issue. CapsuleComponent has many functions exposed, but I don’t think enough is marked ENGINE_API to allow it to be subclassed outside the module. This is the kind of thing we can only really find out when people start trying to do this kind of thing! I made myself a task to fix this before the next release, sorry for the trouble.

Doh :slight_smile: Alright, thanks!

Seems to be the same with serialize for ACamera.

TacticalCamera.cpp.obj : error LNK2019: unresolved external symbol “public: virtual void __cdecl ACameraActor::Serialize(class FArchive &)” (?Serialize@ACameraActor@@UEAAXAEAVFArchive@@@Z) referenced in function “public: virtual void __cdecl ATacticalCamera::Serialize(class FArchive &)” (?Serialize@ATacticalCamera@@UEAAXAEAVFArchive@@@Z)