CPP Blueprint Function Library and USTRUCTS functions problems


Im trying to use BlueprintFunctionLibrary written in cpp to get access to functions inside USTRUCT, and i struggled into this type of problem:

I have a USTRUCT defined with some functions inside:

Example in simplified code :


struct TheStruct
some property


Im also having a separate cpp file with function defintions



Now i have created a BP Function Library that tries to call USTRUCT Functions:

class UprojectBPLib : public UBlueprintFunctionLibrary
void CallFunc1(TheStruct struct);  and in CPP there is a definition { struct.Func1(); }

After having such a setup, the project doesnt compile, it throws Unresolved External Symbol error with Func1()

UprojectBPLib.cpp.obj : error LNK2019: unresolved external symbol “public: void __cdecl TheStruct::Func1()” (?Func1@TheStruct@@QEAAXW4Level@TheStruct@@_N@Z) referenced in function “private: static void __cdecl UprojectBPLib::Func1()” (?Func1@UprojectBPLib@@CAXUFTheStruct@@W4Level@ETheStruct@@_N@Z)

In this case you need #include "projectTypes.h" in the HEADER file (projectBPLib.h).

First, USTRUCT needs a GENERATED_BODY() inside its declaration. Second, its name must begin with the letter ‘F’.
Also, you need to include the *.generated.h header file (where in * you place the name of the header file that contains the struct definition).

I have all the headers in place

Hey, i wrote that i presented you a simplified code. What i have in my project is working correctly until i try to call USTRUCT functions from Blueprint Function Library

Basically the error says that the linker failed to locate the definition of the struct member function. The problem is in the thestruct.h or in the thestruct.cpp somewhere, but it shows up only when you actually call the missing definition.

I tried all the weird combination of includes, to make sure compiler knows about everything - nothing seems to work here. VS is finding all definitions properly from wherever i navigate to them.

My closesed guess is that cpp is not even seen by UnrealBuildTool, because the way you have thigns now UnrealHeaderTool should scream from errors you made in header file as described by XevotPhoenix.

Make sure file is located properly, if you added file in VS file manage, it most likely landed in Intermediate\ProjectFiles insted of Source where UBT don’t look (VS project is not used by UBT at all, it only exist for VS IDE for file editing), as VS sets that as default project directory. IF so, move those file (not with VS, explorer or whatever file manager oyu use) to Source directory to there proper locations and regenerate project files

It is always safest to create files in Source manually and regenerate project files, or at least make sure you add files in proper location (VS let you choose file creation location).

Error suggests that compiler can’t find the definition of TheStruct::Func1()

I just found out that if you create .cpp from Visual Studio, the default path will point to “Intermediate”. Since you’re using a separated .cpp file I’d suggest you checking the path of TheStruct.cpp and make sure it’s under Source/[ProjectName]

If this is not the issue, try moving the function definition into TheStruct block first. I know it’s not ideal but you need to narrow down the issue.

Yea that fixed it, i forgot that it by default creates files in intermediate. Thanks!