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

I am developing custom plugins for our project and want to have ability to check if plugin is loaded and build. Some define directive which would be imported if my project uses this plugin.

Is it possible to do with unreal build system?

I’m currently looking for the same thing. Can you share you solution (if any) ? :slight_smile:

I finally found that you just need to use FModuleManager::Get().IsModuleLoaded("YourModuleName") to check whether or not your plugin is loaded :wink:

I’m not sure if adding some C++ code into your plugin is mandatory or not though. I followed this tutorial here, at the section Stand Alone Plugin

Good luck.
Best regards.

I don’t remember what I need it for ) But IsModuleLoaded solution is not appropriate if you need to switch off some include directives.
But I somehow abandoned that idea and found other solution.
Still having a PLUGIN_ENABLED directive can allow to make some interesting trick with the project.

Also interesting question is how to check if plugin is enabled in Build Scripts.

I agree on that macro trick that would be great. I was mostly looking for “ability to check if plugin is loaded and build” during runtime and I didn’t find anything except your topic here so yeah, I guess it’s fine to put any kind of information related to this topic here anyway :smiley:

Did you ever find a solution for this? I’ve got the same problem, I’d like to check that my module is loaded so that I can safely include a file from it…

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");
						}
                    }
                }
            }
        }
    }
}`