Build errors for derived constaint component

I wanted to make new constraint class to allow dynamic constraint angular offset (for custom vehicle steering wheels).

What I did:

  1. New project - > blank c++

  2. New c++ class with parent “Physics Constraint Component”

  3. Build inside VS - getting this:

    1>------ Build started: Project: TestingConstraints, Configuration: Development_Editor x64 ------ 1> Creating makefile for hot reloading TestingConstraintsEditor (modules to compile have changed) 1> Compiling game modules for hot reload 1> Performing 1 actions (2 in parallel) 1> [1/1] Link UE4Editor-TestingConstraints-9076.dll 1> Creating library D:\UEProjects\TestingConstraints\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-TestingConstraints-9076.lib and object D:\UEProjects\TestingConstraints\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-TestingConstraints-9076.exp 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::BeginDestroy(void)” (?BeginDestroy@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::BeginDestroy(void)” (?BeginDestroy@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostLoad(void)” (?PostLoad@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostLoad(void)” (?PostLoad@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)” (?PostEditChangeProperty@UPhysicsConstraintComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)” (?PostEditChangeProperty@UPhysicsConstraintComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::CheckForErrors(void)” (?CheckForErrors@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::CheckForErrors(void)” (?CheckForErrors@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::OnRegister(void)” (?OnRegister@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::OnRegister(void)” (?OnRegister@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::OnUnregister(void)” (?OnUnregister@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::OnUnregister(void)” (?OnUnregister@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::InitializeComponent(void)” (?InitializeComponent@UPhysicsConstraintComponent@@UEAAXXZ) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::InitializeComponent(void)” (?InitializeComponent@UPhysicsConstraintComponent@@UEAAXXZ) 1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostEditComponentMove(bool)” (?PostEditComponentMove@UPhysicsConstraintComponent@@UEAAX_N@Z) 1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl UPhysicsConstraintComponent::PostEditComponentMove(bool)” (?PostEditComponentMove@UPhysicsConstraintComponent@@UEAAX_N@Z) 1>D:\UEProjects\TestingConstraints\Binaries\Win64\UE4Editor-TestingConstraints-9076.dll : fatal error LNK1120: 8 unresolved externals 1>ERROR : UBT error : Failed to produce item: D:\UEProjects\TestingConstraints\Binaries\Win64\UE4Editor-TestingConstraints-9076.dll 1> Total build time: 5,83 seconds 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3075: The command ““C:\Program Files (x86)\Epic Games\4.13\Engine\Build\BatchFiles\Build.bat” TestingConstraintsEditor Win64 Development “D:\UEProjects\TestingConstraints\TestingConstraints.uproject”
    -waitmutex” exited with code 5. Please verify that you have sufficient rights to run this command.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped

Question is: whats wrong?

You have a series of unresolved symbols:

1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::BeginDestroy(void)" (?BeginDestroy@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::BeginDestroy(void)" (?BeginDestroy@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostLoad(void)" (?PostLoad@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostLoad(void)" (?PostLoad@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UPhysicsConstraintComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UPhysicsConstraintComponent@@UEAAXAEAUFPropertyChangedEvent@@@Z) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::CheckForErrors(void)" (?CheckForErrors@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::CheckForErrors(void)" (?CheckForErrors@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::OnRegister(void)" (?OnRegister@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::OnRegister(void)" (?OnRegister@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::OnUnregister(void)" (?OnUnregister@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::OnUnregister(void)" (?OnUnregister@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::InitializeComponent(void)" (?InitializeComponent@UPhysicsConstraintComponent@@UEAAXXZ) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::InitializeComponent(void)" (?InitializeComponent@UPhysicsConstraintComponent@@UEAAXXZ) 
1>MyPhysicsConstraintComponent.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostEditComponentMove(bool)" (?PostEditComponentMove@UPhysicsConstraintComponent@@UEAAX_N@Z) 
1>TestingConstraints.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UPhysicsConstraintComponent::PostEditComponentMove(bool)" (?PostEditComponentMove@UPhysicsConstraintComponent@@UEAAX_N@Z) 
1>D:\UEProjects\TestingConstraints\Binaries\Win64\UE4Editor-TestingConstraints-9076.dll : fatal error LNK1120: 8 unresolved externals 

This means that you’ve declared these methods in your custom class’s header file, but haven’t defined their functionality in the source file.

Add definitions for each of these methods to your .cpp file, or comment out/remove their declarations in your .h:

BeginDestroy
PostLoad
PostEditChangeProperty
CheckForErrors
OnRegister
OnUnregister
InitializeComponent
PostEditComponentMove

i.e. for Begin Destroy you can either add to your .cpp file:

void UMyPhysicsConstraintComponent::BeginDestroy() {
   ...functionality...
}

Or remove the override declaration from your header.

This error may also be caused by neglecting to modify the class when defining the method in your .cpp file after copying from the parent source:

//if your .cpp file looks like this
void UPhysicsConstraintComponent::BeginDestroy() {
   ...functionality...
}

//it should look like this
void UMyPhysicsConstraintComponent::BeginDestroy() {
   ...functionality...
}

If that doesn’t help, please post the contents of your MyPhysicsConstraint.h and MyPhysicsConstraint.cpp files and we can see if there are other issues.

Class is completly blank. I didn’t do anything except those 3 steps described above:

  • create new blank c++ project
  • create new c++ class derived from PhysicsConstraintComponent
  • build inside VS

Thats all you need to reproduce the problem. I guess there’s something wrong with the way UE handles derived classes for that particular case.

How are you doing step two? Are you creating the c++ class via the editor?

Can you post the contents of the .h and .cpp files?

Yeah, I’m using editor.

header:

#pragma once

#include "PhysicsEngine/PhysicsConstraintComponent.h"
#include "MyPhysicsConstraintComponent.generated.h"

UCLASS()
class TESTINGCONSTRAINTS_API UMyPhysicsConstraintComponent : public UPhysicsConstraintComponent
{
	GENERATED_BODY()
	
	
	
	
};

source:

#include "TestingConstraints.h"
#include "MyPhysicsConstraintComponent.h"

Hey AfterAll14-

's suggestion of the unresolved symbols is correct. If you add a function declaration / empty definition for the functions listed in 's answer you should get your code to compile without issue.

Cheers