Weird LINK2001 and 2019 error

Whenever I compile the code, these two errors appear:

LNK2001 unresolved external symbol “public: __cdecl UKeybindingUMG::UKeybindingUMG(class FObjectInitializer const &)” (??0UKeybindingUMG@@QEAA@AEBVFObjectInitializer@@@Z)

LNK2019 unresolved external symbol “public: __cdecl UKeybindingUMG::UKeybindingUMG(class FObjectInitializer const &)” (??0UKeybindingUMG@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function “public: void __cdecl UKeybindingUMG::`default constructor closure’(void)” (??_FUKeybindingUMG@@QEAAXXZ)

KeybindingUMG.cpp:

// Fill out your copyright notice in the Description page of Project Settings.

#include "KeybindingUMG.h"
#include "Project.h"

KeybindingUMG.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "KeybindingUMG.generated.h"

/**
 * 
 */
UCLASS()
class PROJECT_API UKeybindingUMG: public UUserWidget
{
	GENERATED_UCLASS_BODY()
};

I can’t find anything contextually wrong from this. It would be great if anyone can tell me what have I done wrong.

As you’re using GENERATED_UCLASS_BODY(), you should provide a constructor in your .cpp file.

If you don’t want to write a constructor, you can use GENERATED_BODY() instead

1 Like

Using old GENERATED_UCLASS_BODY() requires you to create constructor in same formul as linking error suggesting, the constructor is called in generated code thats why you don’t see it.

Use new GENERATED_BODY() instead it does not require any constructor the old macro probably will be deprecated sooner or later, just remember with this one you need ot place “public:” as by default any feather declarations in class will be private by default

2 Likes

Thanks! This saved me from several hours of debugging haha

Thanks! This saved me from several hours of debugging haha