UE4 Is there a way to include another file/class from Build.cs or Target.cs

Viewed 429

I want to build a generic cmake library importer for Unreal-Engine 4 plugins. I would like to create another class to handle it and used over multiple plugins. How would I include this new class in the plugins Build/Target.cs file? (https://github.com/caseymcc/UE4CMake)

1 Answers

I did figure out that you can put the needed code into an empty plugin:

public class BuildSource : ModuleRules
{
    public BuildSource(ReadOnlyTargetRules Target) : base(Target)
    {
    }
    ...
    //what ever code you want to include in your builds
    ...
}

Then add the plugin using your uproject/uplugin file with:

{
    "FileVersion": 3,
    "EngineAssociation": "4.25",
    ...
    "Plugins": [
        {
            "Name": "BuildSource",
            "Enabled": true
        }
    ]
}

This will force the code in BuildSource to be compiled into an Assembly and include into your project (no imports needed). If you are using the Editor as well you might need to build an empty class that inherits from IModuleInterface to get it to link properly. Make sure to call IMPLEMENT_MODULE(FBuildSourceEditorModule, BuildSource) to generate the module.

I am currently using that for the code mentioned above (https://github.com/caseymcc/UE4CMake)

Related