C++ How to declare instance to call functions from class?

Hi, Im fairly new to C++ so sorry if this is a stupid question.

I’ve created a custom actor component with a function in it I want to call on another actor.

I’m attempting to declare an instance of DopplerComponentTest and then call my function DopplerUpdatee like this:

UDopplerComponentTest obj;
obj.DopplerUpdatee();

The actor I’m trying to call it from is DopplarActor.cpp

I want to call this function every tick but when I place these two lines in the Tick {} I get this linker error on compiling:

DopplerActor.cpp.obj : error LNK2019: unresolved external symbol “public: void __cdecl UDopplerComponentTest::DopplerUpdatee(void)” (?DopplerUpdatee@UDopplerComponentTest@@QEAAXXZ) referenced in function “public: virtual void __cdecl ADopplerActor::Tick(float)” (?Tick@ADopplerActor@@UEAAXM@Z)

I’ve tried declaring obj in the beginplay function of my actor.cpp but then obj can’t be referenced in the tick function.

Any help greatly appreciated thanks as I’ve only started trying to teach myself cpp this week.

LNK2019 means the declaration of your class is missing somehow, check if you included it in you Actor’s .cpp file:

#include "MyPath/DopplerComponentTest.h"

Or something like that. Also, check if the module is missing in your Build.cs file. If the declaration exists and is correct. And reload your project’s code base.


Additionally, to initialize a new UObject you must use Unreal’s framework method.

UDopplerComponentTest* Obj = NewObject<UDopplerComponentTest>(nullptr)

  • Check the many overloads of the NewObject function.

Awesome thanks! I’ve fixed the link error but now I’m having trouble choosing where to initilialize the UObject as I don’t want to be Initializing a new object every tick, but I do want to call a function from said object every tick.

However when I try and initialize the object in the header file or the beginplay function of the .cpp file, it won’t allow me to reference the object within the tick function as it’s been initialized in another function.

I’m now getting these errors,

C:\Users\User\Documents\Unreal Projects\WwiseCPlusPlus\Source\WwiseCPlusPlus\DopplerActor.cpp(74): error C2228: left of ‘.DopplerUpdatee’ must have class/struct/union
C:\Users\User\Documents\Unreal Projects\WwiseCPlusPlus\Source\WwiseCPlusPlus\DopplerActor.cpp(74): note: type is ‘UDopplerComponentTest *’
C:\Users\User\Documents\Unreal Projects\WwiseCPlusPlus\Source\WwiseCPlusPlus\DopplerActor.cpp(74): note: did you intend to use ‘->’ instead?

I tried using obj->DopplerUpdatee(); instead of obj.DopplerUpdatee(); but it caused another link error .