How can I share a library module between projects?

I have some code (UObject-derived classes, helper functions, etc) which I want to reuse in multiple projects. I am sure this must be a common requirement, but am struggling to find any explanation or example of how to do it.

I assume, since the code will make use of the UE4 reflection system, that I need to create a module to encapsulate it. However, while there is some information about adding modules, everything I can find is related to adding a module to an existing project. I want the module to exist above all my projects in the directory structure, since I obviously want to only maintain a single copy of this code.

Writing a plugin may work, but seems like a misuse since I really want a static dependency.

I guess adding a module to the engine itself would be another way, but if possible Iā€™d really prefer to avoid making my projects dependent on a non-standard engine build.

Is there a simpler way to achieve this?

I got around this problem by using git submodules, so essentially offloading the copying and syncing of shared code to the source control. This works, however it feels like an imperfect solution. If anyone has a better approach, such as a way to avoid the restriction on module code having to be located within the project directory, please share.

@kamrann - how did you get your module set up so that you could use the UObjects and other classes in the editor?

A plugin is a container/collection of modules.

So create a plugin and host its code separately from your projects and use P4V streams or git submodules to import the plugin into your various consuming projects plugin folders.

Add your shared code as a module to the plugin, and add the module (not the plugin) as a module dependency to your projects.

Whether you create a module in a plugin or a module on your main project makes no difference, in modular builds UBT creates a dll for each module, regardless of how it was sourced.

1 Like