Get a define in code if plugin is loaded and build into project.

I was able to achieve this. The following code is from the build.cs file of the main module of my plugin, but should work normally on the project’s build.cs file too.

`public class StreamlinePlatform : ModuleRules
{
	public StreamlinePlatform(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
			}
		);

		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"DeveloperSettings",
				"Engine",
				"OnlineSubsystem",
				"OnlineSubsystemUtils",
			}
		);

		UnsafeTypeCastWarningLevel = WarningLevel.Error;

		StreamlinePlatform.ConfigurePlugins(this, Target);
	}

	static public void ConfigurePlugins(ModuleRules Rules, ReadOnlyTargetRules Target)
	{
        if (Target.bUsesSteam == true)
        {
			Rules.PublicDefinitions.Add("WITH_STEAM=1");
        }

        JsonObject RawObject;
		if (JsonObject.TryRead(Target.ProjectFile, out RawObject))
		{
			JsonObject[] pluginObjects;
			if (RawObject.TryGetObjectArrayField("Plugins", out pluginObjects))
			{
                foreach (JsonObject pluginObject in pluginObjects)
                {
                    string pluginName;
                    pluginObject.TryGetStringField("Name", out pluginName);

                    bool pluginEnabled;
                    pluginObject.TryGetBoolField("Enabled", out pluginEnabled);

                    if (pluginName == "OnlineSubsystemSteam" && pluginEnabled)
                    {
						if (Target.bUsesSteam == false)
						{
							Rules.PublicDefinitions.Add("WITH_STEAM=1");
						}
                    }
                }
            }
        }
    }
}`
1 Like