WithServer not working as it should ?

So i have a simple bool function that reruns true if this build was a server build and flase otherwise here is the code :



bool UMyBlueprintFunctionLibrary::serverbuild(){
#if WITH_SERVER
return true;
#else
return false;
#endif


}



the problem is when i build a dev_server build and run the dedicated server -log , the function always return false !

here is also my buildtarget file :


using UnrealBuildTool;
using System.Collections.Generic;

public class MyProject2ServerTarget : TargetRules
{
    public MyProject2ServerTarget(TargetInfo Target)
    {
        Type = TargetType.Server;
    }

    //
    // TargetRules interface.
    //
    public override void SetupBinaries(
        TargetInfo Target,
        ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
        ref List<string> OutExtraModuleNames
        )
    {
        base.SetupBinaries(Target, ref OutBuildBinaryConfigurations, ref OutExtraModuleNames);
        OutExtraModuleNames.Add("MyProject2");
    }

    public override void SetupGlobalEnvironment(
        TargetInfo Target,
        ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
        ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
        )
    {
        if (UnrealBuildTool.UnrealBuildTool.IsEngineInstalled())
        {
            UEBuildConfiguration.bCompileLeanAndMeanUE = true;

            // Don't need editor or editor only data
            UEBuildConfiguration.bBuildEditor = false;
            UEBuildConfiguration.bBuildWithEditorOnlyData = false;

            UEBuildConfiguration.bCompileAgainstEngine = true;

            // no exports, so no need to verify that a .lib and .exp file was emitted by the linker.
            OutLinkEnvironmentConfiguration.bHasExports = false;
        }
        else
        {
            // Tag it as a UE4MyProject2 build
            OutCPPEnvironmentConfiguration.Definitions.Add("UE4GAME=1");
        }
    }

    public override bool GetSupportedPlatforms(ref List<UnrealTargetPlatform> OutPlatforms)
    {
        // It is valid for only server platforms
        return UnrealBuildTool.UnrealBuildTool.GetAllServerPlatforms(ref OutPlatforms, false);
    }

    public override List<UnrealTargetPlatform> GUBP_GetPlatforms_MonolithicOnly(UnrealTargetPlatform HostPlatform)
    {
        if (HostPlatform == UnrealTargetPlatform.Mac)
        {
            return new List<UnrealTargetPlatform>();
        }
        return new List<UnrealTargetPlatform> { HostPlatform, UnrealTargetPlatform.Win32, UnrealTargetPlatform.Linux };
    }

    public override List<UnrealTargetConfiguration> GUBP_GetConfigs_MonolithicOnly(UnrealTargetPlatform HostPlatform, UnrealTargetPlatform Platform)
    {
        return new List<UnrealTargetConfiguration> { UnrealTargetConfiguration.Development };
    }
}

Any help would be appreciated !

It is called:

WITH_SERVER_CODE

It will be 1 when you select the “Debug Server” or “Development Server” configuration option.

Try:



bool UMyBlueprintFunctionLibrary::serverbuild()
{
	return WITH_SERVER_CODE;
}


Worked like a charm , thanks Azarus

I’m glad i was able to help! :slight_smile: