Problem occuring when packaging my C++ code plugin

Hi everyone,

I’ve been trying to package my C++ code plugin, but I have an error on which I’ve been stuck for a while.

Here is my BlueprintFunctionLibrary (GlobalFunctions.h):

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GlobalFunctions.generated.h"

class UTimerTask;

class STATSCREATOR_API UGlobalFunctions : public UBlueprintFunctionLibrary

        static void AddGlobalTimerTask(const FName GlobalTimerName, UObject* InvolvedObject, const TSubclassOf<UTimerTask> TimerTask);

This library also contains other functions that works fine and are irrelevant here.
When I compile the code, everything works, and I can use it as intended in the editor.
However, when I try to package the plugin, I get this error:

UATHelper: Package Plugin Task (Windows): E:\UE4 Plugins\StatsComponent\StatsCreator\StatsCreator\HostProject\Plugins\StatsCreator\Source\StatsCreator/Public/GlobalFunctions.h(15): error C2664: ‘void UGlobalFunctions::AddGlobalTimerTask(const FName,UObject *,const TSubclassOf<UTimerTask>)’: cannot convert argument 3 from ‘UClass *’ to ‘const TSubclassOf<

I get this error regardless of the function definition, as I’ve tried to remove it to see if it would package, but nope.
If I remove this function and every call to it in my project, my plugin packages.

Please note that I use plenty of "TSubclassOf<…>’ as function parameters in my plugin and I’ve never encountered this error.

If a gentle soul can help me with this, it would be greatly appreciated.
If you need more information regarding the issue, feel free to ask me.

Have a nice day/evening!

By the time your UGlobalFunctions’ CDO is built, your forward declared class UTimerTask is still undefined.
That causes packaging to fail.

Thanks for your reply.
I’m still pretty new in C++. Can’t I use forward declared classes when I’m using ‘TSubclassOf<…>’?
Also I’ve already tried to include the “TimerTask.h” header file, and I get the same error.
Was that what you were suggesting?

It looks like UHT being weird, the error is in the UFUNCTION macro. Try adding a Category specifier there. Also, remove ‘const’ from the name and class parameters - it does nothing in that context, and things like that can screw up UHT.

Worth manually clearing out your Intermediate folders too (project and plugin) just in case.

There should be no issue with the forward declaration here, that looks totally standard. It only needs to be defined at the point at which you pass an argument to the function from a caller.

Thank you kamrann. I was really optimistic about your answer.

The steps I’ve taken:
I’ve added a Category specifier in the UFUNCTION() macro,
I’ve removed ‘const’ from the parameters as you pointed out,
I’ve manually cleared the Intermediate folders for both my project and plugin,
I’ve deleted my Visual Studio Solution (.sln) and regenerated my Visual Studio Project Files.

Unfortunately I still get the same error. Am I missing something?

Been having the same problem. Could only solve it by including the .h file containing the template type (anywhere above #include “***.generated.h”)… I don’t like it, but it works.

What I don’t understand though is why I only get this error when Packaging the plugin, and not when Building from Visual Studio or Compiling from the Editor?

Editor modules usually load a plethora of additional classes and often what you’re using is already included somewhere else… When packaging then all included headers by editor are gone and you notice your module isn’t well-formed.