How to see what platform game is running on?

In c++, how do I see what platform the game is currently running on/compiled for?

Do you mean something like this?

This is an extract of the ShooterGame. I guess you can use this if statement in your normal class too:

if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Linux) || (Target.Platform == UnrealTargetPlatform.Mac))
		{
			if (UEBuildConfiguration.bCompileSteamOSS == true)
			{
				DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
			}

			DynamicallyLoadedModuleNames.Add("OnlineSubsystemNull");
		}
		else if (Target.Platform == UnrealTargetPlatform.PS4)
		{
			DynamicallyLoadedModuleNames.Add("OnlineSubsystemPS4");
		}
        else if (Target.Platform == UnrealTargetPlatform.XboxOne)
        {
            DynamicallyLoadedModuleNames.Add("OnlineSubsystemLive");
        }

I just took the whole part. Only the ifs are insteresting for your though.

Basically, C++ compile your source code to run on your machine Win/Mac, However, Inside the editor,You will have the ability to build your game to run on a different platform such as Android.

this means VS only build your game to run through your engine on Win/Mac platform, while The Editor itself who is responsible for building your final game to run on others platforms.

If I missed something, Please someone fixed it.

Best of luck

Thank you for the answer but that doesn’t answer my question. The question was: how do I, in code, see what platform my game is running on?

Hi Halliom,

You can try to use this:

UGameplayStatics::GetPlatformName();

Also, if you want add some platform depended code you can use this macros

    PLATFORM_MAC
    PLATFORM_WINDOWS
    PLATFORM_LINUX
    PLATFORM_IOS
    PLATFORM_ANDROID
    WITH_EDITOR

Hope it helps!

Thanks that was just what i was looking for!

How do I check in C++ module, instead of UBT C#, if the target platform is x32 or x64?

Just like we do in .Build files, but I need this to load a dynamic DLL and need to check if the game built will be 64bits or not…

Edit:
Found it, just need to use #PLATFORM_32BITS directive.