Download

Packaged game not creating an object of an UObject class on MacOS

Hello!

I’m trying to package the default Unreal’s FPS project with addition of a custom class using the BuildCookRun command -
<path_to_UE>/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -nop4 -project=<path_to_uproject_file> -build -cook -stage -archive -archivedirectory=<some_path>/dist -targetplatform=Mac -target=<target_project_name> -nocompileeditor -nodebuginfo -serverconfig=Development -clientconfig=Development -package -pak -prereqs

Custom class added to the project;
IssueTest.h

...

UCLASS()
class UIssueTest : public UObject
{
    GENERATED_BODY()

public:
    UIssueTest(const FObjectInitializer& ObjectInitializer =
                       FObjectInitializer::Get());
};

IssueTest.cpp

...

struct FObjectLoader
{
    FDelegateHandle PostEngineInitHandle;
    FObjectLoader()
    {
        UE_LOG(LogTemp, Warning, TEXT("FObjectloader created!!!"));
        PostEngineInitHandle = FCoreDelegates::OnPostEngineInit.AddLambda(
            [this]() { OnPostEngineInit(); });
    }

    void OnPostEngineInit()
    {
        UE_LOG(LogTemp, Warning, TEXT("FObjectLoader: OnPostEngineInit"));
    }

    ~FObjectLoader()
    {
         UE_LOG(LogTemp, Warning, TEXT("~FObjectLoader is called!!!"));
         FCoreDelegates::OnPostEngineInit.Remove(PostEngineInitHandle);
    }
};

static FObjectLoader Loader;

UIssueTest::UIssueTest(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
    UE_LOG(LogTemp, Warning, TEXT("IssueTest: Constructor"));

    FCoreDelegates::OnPostEngineInit.AddLambda(
            [this]() {UE_LOG(LogNew, Warning, TEXT("IssueTest: OnPostEngineInit"));});
}

MacOS - Catalina
UE version - 4.25

What is the issue?
The above build command outputs a .app file. Upon launching, none of the log statements from FObjectLoader struct are printed, i.e. FObjectLoader object is not being created. I’m not sure why this is happening.

Another thing I observed is that during packaging using the above command, FObjectLoader struct log statements are printed, i.e. an object of FObjectLoader is created. I’m assuming UE is launching Engine to cook contents, and in this process, the object is created. But, what I don’t understand is why isn’t an object of FObjectLoader created when I launch the packaged .app.

Any inputs are appreciated!
Cheers!