Adding Custom Module to UE4 Project

Hi

Im trying to follow the example from here for adding a custom module

https://answers.unrealengine.com/questions/83000/modules-project-organisation-and-plugins.html

However the example given is for extending editor, and its unclear what TargetType to use in the Target file for the new module and what to use in the Module section of the .uproject file if you are just trying to add a new module for say reusable code.

I am using new 4.5 engine, if I follow instructions exactly for Editor example but use TargetType.Game for my custom module (as its not an Editor) UnrealBuildTool complains when generating the project files

UnrealBuildTool Exception: ERROR: Not expecting project Intermediate\ProjectFiles\Sandbox1.vcxproj to already have a target rules of with configuration name RocketGame (GameFrameworkTarget) while trying to add: Sandbox1Target

(Sandbox1 is Unreal project and GameFramework is module Im trying to add for reusable code)

Thanks in advance for any help

Are you adding a new .Target.cs file for your module? If so, you don’t need to do that - the only reason the editor adds a new target is because we don’t yet have an editor target file, but we do already have a game target file. If you were adding a second editor specific module, you wouldn’t add a second target file for it.

It should just be a case of making sure your “GameFramework” module is referenced as a dependency of your main game module - UBT should then pick up that something is referencing the module and build it.

Thanks! That solved the problem.

So you would only add a new Target file if you are building a new TargetType like Client or Server?

Exactly, yeah.

A target simply defines an application/executable. Each target can be comprised of multiple modules, and a single module can be used by multiple targets.

Ok so I have my custom module up and running, I can extend classes from there, I can add classes to it from the “Add Code To Project” dialog, however I am unable to select a class from my framework to extend in the “Add Code To Project” dialog unless I use

UCLASS(MinimalAPI)

Is there some other UCLASS modifier that would allow me to add classes to the project that extend my own custom classes?

Thanks

Ah… by default the class validation won’t let you derive from things that aren’t available to the default game module.

We probably need to move the module selection combo to the first page, so that you can specify which module you’re adding the class to.

The class validation is already linked to the selected module though, so you might be able to select “None”, go to the next page, then select your module from the combo, then go back and actually select the class you want.

Hey Jamie

Just to be clear … I can see my classes in the add code to project if i select show all classes, and derive from them successfully.

The only way I have been able to achieve this however is to use the following UCLASS declaration on my classes in my custom module

UCLASS(MinimalAPI)

If I use any of the following

UCLASS()
UCLASS(Abstract)

for example … then they do not appear in the Add Code to Project dialog.

Is there a reason for this? Is there another class modifier or a specific set of modifiers that would allow my classes to appear in the show all classes list in Add Code to Project?

The only issue with MinimalAPI is that I would have to mark any properties or functions with RequiredAPI modifier that I want to be available to the subclass (based on my reading) which is cumbersome and prone to user error

Thanks for all your help so far!

You can see your classes when they’re tagged that way because it makes them available to use as a base class in other modules (like you game module). The same should also be true for any classes in your module that are public and have the API macro on them (eg MYMODULE_API).

Are you wanting to add the new classes to your main game module, or the new module you added before?

Right, so that should be no different than a standard engine module.

You’ll need to make sure that your class is publicly accessible to other modules (if you’re using the Public/Private folder layout for your module, then the class should be in Public - if you’re not using that layout, then all classes will be treated as Public).

You then need to make sure that your class is tagged with the API macro for your module. This is MODULENAME_API, eg, if your module was called “Wooble”, then this would be WOOBLE_API. If you take a look at AGameMode in the engine, you’ll see that it has an ENGINE_API macro on it.

Once you’ve done that and built, you should see the classes available in the class wizard.

Im trying to create some reusable classes that provide default behaviour, for example BaseGameMode and BaseGameState. I would like these to be in my custom module so I can use them in any uproject that I create.

This question only applies to those classes that extend UE4 Gameplay classes where I would like to use my base class when adding GameMode, GameState, AIController, Actor types, etc to my uproject in the UE4 editor.

For those specific types of classes everything works great if I use MinimalAPI, Im just asking if there is another way to make them available to my game module and the UE4 Add Code to Project that doesnt require me to decorate every property and function I add to my base classes with RequiredAPI?

My understanding of MinimalAPI …, which admittedly may be minimal ;o) … is that it exposes only the class type for quick compilation and linking, but none of the functionality or properties, these would need to be marked with RequiredAPI to expose them to the game module class?

Sorry for long winded attempts to describe question :oP

Appreciate your responses

Ok got it! Let me try that

Thanks

As you are no doubt aware, that works perfectly

Thanks very much :o)