Download

Check if game is in foreground issue

Hi, I’ve created a new blueprint function library class called “CheckForeground” it’s really simple, I am on 4.22 engine version

The code on Visual Studio is flawless, I mean absolutely no errors :frowning: But when I go to UE4 Editor and click compile it always fail.

Can you please tell me what I’m doing wrong (the header and the source files are samples)?

IsApplicationForegroundNow.h



#pragma once

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

/**
 *
 */
UCLASS()
class GAMESAMPLE_API UIsApplicationForegroundNow : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:

    UFUNCTION(BlueprintPure, Category = "foreground")
        static bool IsApplicationForegroundNow();

};



IsApplicationForegroundNow.cpp



#include "GameSample.h"
#include "IsApplicationForegroundNow.h"


#include "Runtime/ApplicationCore/Public/HAL/PlatformApplicationMisc.h"



bool UIsApplicationForegroundNow::IsApplicationForegroundNow()
{
    return FPlatformApplicationMisc::IsThisApplicationForeground();    
}


Message Log




  IsApplicationForegroundNow.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl FWindowsPlatformApplicationMisc::IsThisApplicationForeground(void)" (__imp_?IsThisApplicationForeground@FWindowsPlatformApplicationMisc@@SA_NXZ) referenced in function "public: static bool __cdecl UIsApplicationForegroundNow::IsApplicationForegroundNow(void)" (?IsApplicationForegroundNow@UIsApplicationForegroundNow@@SA_NXZ)

C:\Users\pc\Documents\Unreal Projects\GameSample\Binaries\Win64\UE4Editor-GameSample-4972.dll : fatal error LNK1120: 1 unresolved externals



Why say that is unresolved external, I can view the file PlatformApplicationMish correctly!

Thanks for all your help in advance :slight_smile:

Try to add this line of code to your *.Build.cs file.


PrivateDependencyModuleNames.AddRange(new string] { "ApplicationCore" });

Wow! 5 seconds fix :slight_smile: !
Lesson learned, so I will have to check also the dependancy in the build.cs file.

https://docs.unrealengine.com/en-US/API/Runtime/Core/Misc/FFileHelper/index.html
[TABLE=“cellspacing: 0”]

Module
ApplicationCore

Header
/Engine/Source/Runtime/ApplicationCore/Public/Lumin/LuminPlatformApplicationMisc.h

Include
#include “Lumin/LuminPlatformApplicationMisc.h”

Now in the table has come to my attention the line Module in the C++ Api documentation, is the line to check every time, isn’t that right?
And the header line is suppsed to do a check for yourself, like go manually with file explorer, or can be used as a real include on the c++ file without the include?

I ask because I want to learn how that works in order to not have those issues next time :slight_smile: