UE 4.17.2: Unresolved External when extending UPhysicsHandleComponent

Explanation of the Issue

Simply adding a new class extended from class UPhysicsHandleComponent (@Runtime/Engine/Classes/PhysicsEngine/PhysicsHandleComponent) results in an error regarding unresolved external symbol related to UPhysicsHandleComponent::UpdateDriveSettings().

Steps to reproduce

  1. Create new C++ project or use any existing project
  2. In Content Browser add new class extended from “PhysicsHandleComponent”.
  3. Compile will fail with error shown in Log below
  4. The solution is now corrupted and needs to be cleaned out by deleting the new class & Intermediate folder, and regenerating the VS files.

Log

Candidate modules for hot reload:
PWNGame
Launching UnrealBuildTool… [C:/UnrealEngines/UE_4.17/Engine/Binaries/DotNET/UnrealBuildTool.exe PWNGame -ModuleWithSuffix PWNGame 8150 Win64 Development -editorrecompile -canskiplink “E:/UE4/TheFifthEstate/V008/PWNGame/PWNGame.uproject” ]
CompilerResultsLog: New page: Compilation - 12 Oct 2017, 7:54:21 AM
CompilerResultsLog: Performing full C++ include scan (hot reloading a new target)
CompilerResultsLog: Compiling game modules for hot reload
CompilerResultsLog: Parsing headers for PWNGameEditor
CompilerResultsLog: Running UnrealHeaderTool “E:\UE4\TheFifthEstate\V008\PWNGame\PWNGame.uproject” “E:\UE4\TheFifthEstate\V008\PWNGame\Intermediate\Build\Win64\PWNGameEditor\Development\PWNGameEditor.uhtmanifest” -LogCmds=“loginit warning, logexit warning, logdatabase error” -Unattended -WarningsAsErrors -installed
CompilerResultsLog: Reflection code generated for PWNGameEditor in 6.6174089 seconds
CompilerResultsLog: Performing 5 actions (4 in parallel)
CompilerResultsLog: PWNPhysicsHandleComponent.cpp
CompilerResultsLog: PWNGame.init.gen.cpp
CompilerResultsLog: PWNPhysicsHandleComponent.gen.cpp
CompilerResultsLog: [4/5] Link UE4Editor-PWNGame-8150.dll
CompilerResultsLog: [5/5] Link UE4Editor-PWNGame-8150.lib
CompilerResultsLog: Creating library E:\UE4\TheFifthEstate\V008\PWNGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-PWNGame-8150.lib and object E:\UE4\TheFifthEstate\V008\PWNGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-PWNGame-8150.exp
CompilerResultsLog: Creating library E:\UE4\TheFifthEstate\V008\PWNGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-PWNGame-8150.suppressed.lib and object E:\UE4\TheFifthEstate\V008\PWNGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-PWNGame-8150.suppressed.exp

** CompilerResultsLog: Error: PWNPhysicsHandleComponent.cpp.obj : error LNK2001: unresolved external symbol “protected: virtual void __cdecl UPhysicsHandleComponent::UpdateDriveSettings(void)” (?UpdateDriveSettings@UPhysicsHandleComponent@@MEAAXXZ)**

CompilerResultsLog: Error: PWNPhysicsHandleComponent.gen.cpp.obj : error LNK2001: unresolved external symbol “protected: virtual void __cdecl UPhysicsHandleComponent::UpdateDriveSettings(void)” (?UpdateDriveSettings@UPhysicsHandleComponent@@MEAAXXZ)
CompilerResultsLog: Error: E:\UE4\TheFifthEstate\V008\PWNGame\Binaries\Win64\UE4Editor-PWNGame-8150.dll : fatal error LNK1120: 1 unresolved externals
CompilerResultsLog: ERROR: UBT ERROR: Failed to produce item: E:\UE4\TheFifthEstate\V008\PWNGame\Binaries\Win64\UE4Editor-PWNGame-8150.dll
CompilerResultsLog: Total build time: 11.64 seconds (Local executor: 0.00 seconds)
LogMainFrame: MainFrame: Module compiling took 11.816 seconds

Hey staticvoidlol-

The reason the unresolved external errors is because the PhysicsHandleComponent UCLASS macro has the MinimalAPI specifier. This specifier is meant to only expose the bare minimum of the class to improve overall compile times. If you’re using the editor built from source, you can remove MinimalAPI from PhysicsHandleComponent.h which should prevent the unresolved external errors.

Cheers

Thanks very much for the swift response . Fair enough, but is there any way to extend PhysicsHandleComponent without having to build the engine from source?

I’m going to post a different solution that doesn’t require building the engine from source.

It’s actually pretty simple but not ideal. I did this as follows:

  1. Create new class derived from ActorComponent

  2. Copy/paste the PhysicsHandleComponent code into it

  3. Ensure that you include PhysX in your Game.build.cs file:

    PrivateDependencyModuleNames.AddRange(new string[] { “PhysX”, “APEX” });

  4. Use the parameterless constructor instead of the ObjectInitializer one.

  5. Replace all occurrences of “UPhysicsHandleComponent::” in the cpp file with your class name.

  6. Fix up the includes

I’m attaching the files here, but they can also be found in my BitBucket repo . If anyone else wants to use these, first check step 3 above, and then replace all occurrences if “UPWNPhysicsHandleComponent” with your class name, or create the class with “PWNPhysicsHandleComponent” as the name in editor.