UE4 build sytem: how do I add an Actor Class to the engine source

Hi,

is the UE4 build system documented somewhere? I am unable to figure out how to add a new Actor class, it’s factory etc., to the engine source.

Mostly the auto generated header files are a mistery to me.

I would like to add some Actor classes ( something similar in structure like the CameraActor ) to the editor so I don’t have to do it manually for each new project I build.

Thanks for any insights or links.

Easiest way I have found is to create new folders in Runtime\Engine\Private and Runtime\Engine\Public for your code, in the Public folder you created place your .h and in the Private folder place your .cpp. In your .cpp make sure the first include is #include “EnginePrivate.h” and make sure that your class has ENGINE_API if you need to access it from outside the engine module. ie class ENGINE_API MyNewAction : public AActor

And thats it, your code should now compile and be included as part of the engine. And should be accessible to your game modules.

For the factory you will probably want to add that to Editor/UnrealEd/Private/Factories along with the other factories, and this will also ensure that its only accessible from within the editor. Make sure the .cpp has #include “UnrealEd.h” as the first include.

EDIT: Do as suggested.

Hi ,

I’d recommend creating a instead of editing engine source directly. This will still let you share the code across multiple projects, but doesn’t require any engine modifications or risk collisions with future engine updates. It also lets you group related code together, so if you need to make a details panel customization for your new class, you don’t have to also edit the DetailsCustomization module in the editor, but can just create a new editor module in your .

As a reference, the Paper2D has examples of engine + editor classes being introduced in a , and does a lot of the common things you might need if you introduce a new asset type (asset type actions, thumbnail renderer, factories, etc…), although just adding a new actor class doesn’t need any of those ancillary classes.

[edit: 500th post, woo!]

Cheers,

Thanks guys,

a seems to be the cleaner solution, yes.
I am not sure everything I am planning will be possible to do as a . I am just getting to know the UE4 source…

Since I also want to manipulate the viewport, the OculusRift seems to be a good place to start…

.

Ok, now I am trying to figure out the build system for the plugins…

The empty is being loaded and listed in the editor. So far so good.
I am failing in adding an actor class to the . Using the same code as in a project.


error C1189: #error :  "STATS must be defined as either zero or one."	D:\engines\Unreal\Unreal Engine\4.4\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h

following this wiki link:
I have added a to a project of mine, then I added an empty class to get vc solution file.
How can I add the file to the solution, which is being recreated automatically.

Sorry for the noob questions, seems I am missing something…

.

In the editor, select File>Rebuild Visual Studio Solution. When you exit the editor, VS will ask you to reload. Say yes and your game project should now have the folder.

Thanks, that helped. Only the code needs to be added after the editor is running, or the editor won’t start at all because the is not compiled yet…

I have started with the UObjectPlugin, changed the name of the , and it seems to compile, although there is no functionallity inside, yet.

Then I changed the SuperClass from UObject to AActor, since I want to add an AActor to my :
(I did change the Class name from UMyPluginObject to AMyPlugin…)

*“Build.bat” stops with an error code: 2. *

For some reason the *_generated.h" file fails to be created.

Any more tipps? I am stuck…

.

Are you building it from the editor, from VS or from the command line? I haven’t run anything from build.bat, I use either VS build solution and find the output in the output window or in the editor.

Only from VS. In the output window the Rebuild.bat error occurs:


1>  Parsing headers for PluginTest05Editor
1>LogCompile : error : Duplicate class name: AActor also exists in file /Script/ACameraPlugin
1>D:/engines/Unreal/Unreal Projects/PluginTest05/Plugins/ACameraPlugin/Source/ACameraPlugin/Classes/MyPluginCamera.h(22): error : Superclass Actor of class MyPluginCamera not found
1>D:/engines/Unreal/Unreal Engine/4.4/Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationData.h(45): error : Superclass Actor of class NavigationData not found
...
1>Error : Failed to generate code for PluginTest05Editor - error code: 2
1>  UnrealHeaderTool failed for target 'PluginTest05Editor' (platform: Win64, module info: D:\engines\Unreal\Unreal Projects\PluginTest05\Intermediate\Build\Win64\PluginTest05Editor\Development\UnrealHeaderTool.manifest).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(43,5): error MSB3073: The comman ""D:\engines\Unreal\Unreal Engine\4.4\Engine\Build\BatchFiles\Rebuild.bat" PluginTest05Editor Win64 Development "D:\engines\Unreal\Unreal Projects\PluginTest05\PluginTest05.uproject" -rocket" wurde mit dem Code 2 beendet.

This is especially strange to me:
1>LogCompile : error : Duplicate class name: AActor also exists in file /Script/ACameraPlugin
There is no “Script” folder anywhere.

.

In this case Script is not a folder, it’s an internal namespace of sorts used to reference UObject classes. I haven’t encountered this error before, can you post your code?

This is what we need to help you with your problem, please be sure to post it in the future when you ask.

Check your code for


class AActor

. You shouldn’t be declaring anything like that. There is already a definition for AActor in the Engine code.

You misspelled AActor as “Actor” in your


class MyPluginCamera  : public AActor

line.

Hi,
I thought to keep it short, so here is the relevant code, but I can also upload the complete source, which is similar to the UObjectPlugin.

MyPluginCamera.h:


#pragma once

#include "MyPluginCamera.generated.h"


/**
 * Example UStruct declared in a  module
 */
USTRUCT()
struct FMyPluginStruct
{
	GENERATED_USTRUCT_BODY()
 
	UPROPERTY()
	FString TestString;
};
 

/**
 * Example of declaring a UObject in a  module
 */
UCLASS()
class AMyPluginCamera : public AActor
{
	GENERATED_UCLASS_BODY()

public:

private:

	UPROPERTY()
	FMyPluginStruct MyStruct;

};


MyPluginCamera.cpp:


#include "ACameraPluginPrivatePCH.h"
#include "MyPluginCamera.h"


AMyPluginCamera::AMyPluginCamera( const FPostConstructInitializeProperties& PCIP )
	: Super( PCIP )
{
}

What’s interesting is, when I rename the class to “UMyPluginCamera” and make it an “UObject”, then it compiles just fine. (although IntelliSense keeps complaining about missing includes, but that’s something else, I think)

I do have over 20 years of “practical” C/C++ experience, so deciphering compiler errors is not new to me, but I don’t understand what the build system is doing, or not doing, in the background.

Thanks for your help.
.


D:/engines/Unreal/Unreal Engine/4.4/Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationData.h(45): error : Superclass Actor of class NavigationData not found

I just noticed this was in the Engine source. Did you make changes to the engine source or did you do a global search and replace? It should read



class ENGINE_API ANavigationData : public AActor


and it shouldn’t be giving you a compile error. I also have 4.4 and see that line at 46, not 45 like your error shows. You might check to see if your source still matches the repository.

Yeah, the build system they use is kind of strange and takes some figuring out. I spent a lot of time looking through UnrealBuildTool to figure it oout.

Just looked at UObjectPlugin and I think I know what your problem is.

In your Build.cs file, in the PublicDependencyModuleNames.AddRange, add a third line that says “Engine” after the other two strings. This tells UBT to reference the Engine module, which is where all the Game Framework classes like AActor live…

You can also add include “Engine.h” to your PCH file as well, although I don’t think it’s strictly necessary.

Thanks You fixed it! :slight_smile:


D:/engines/Unreal/Unreal Engine/4.4/Engine/Source/Runtime/Engine/Classes/AI/Navigation/NavigationData.h(45): error : Superclass Actor of class NavigationData not found

I just noticed this was in the Engine source. Did you make changes to the engine source or did you do a global search and replace? It should read



class ENGINE_API ANavigationData : public AActor


and it shouldn’t be giving you a compile error. I also have 4.4 and see that line at 46, not 45 like your error shows. You might check to see if your source still matches the repository.

[/QUOTE]

It’s the same line. Somehow the UCLASS macro forces the error line to be one off. Those errors were just popping up because of the missing headers, I guess. I haven’t touched the source.

Adding the “Engine” module in the Build.cs script AND including “GameFramework/Actor.h” in MyPluginCamera.h did the trick.

Now I can start coding… (need to check the changes made from 4.2 to 4.4)

Thanks for helping me out!
.

One more question please:

I am trying to derive a class from ACameraActor and I am getting unresolved symbols linker errors such as:

“public: virtual void __cdecl ACameraActor::Serialize(class FArchive &)” (?Serialize@ACameraActor@@UEAAXAEAVFArchive@@@Z)".

“Engine” is added to the modules list in the Build.cs file.

.

ACameraActor::Serialize() is not marked for export so it can’t be accessed or overridden outside the module its defined in. File a bug report about this on AnswerHub. In the meantime you can fix this in your own fork of the engine source by prefixing that method declaration with ENGINE_API.

So what is the intent and use cases for having ENGINE_API? It seems pretty arbitrary what Epic intends to be allowed to be derived from. Why not just allow allow all Engine classes to be derived if the programmer wants instead of having to request engine changes and/or manually making the engine change?

If a programmer wanted to derive from a non ENGINE_API class or method, there is access to the engine to do so, but would just cause merge headache.
Many of the forum posts I’ve seen that have these issues, someone at Epic requests a change to the api anyway.

Is it for dll function export encapsulation at the consumer level (i.e. hacking)?

Finally, is it Epic’s recommendation licensees create plugins for any non-ENGINE_API classes and functions?

Just curious.

Thanks,

Sorry for bumping this old thread, but the old solution doesn’t seem to work anymore as EnginePrivate.h no longer exists and I keep including different headers but UCLASS always gives me a “missing type specifier” error. I’m aware of why it may not be a good idea to directly modify the engine because of future potential merge issues and that I may break it more than I actually improve it. But I’m still planning on doing it(unless it’s against the terms of agreement but I haven’t read anything like that) so I was wondering if anyone has a recent work around? I’m trying to add new blueprints for engine changes that I’m making but I can’t get UCLASS to compile no matter what I do and the editor won’t allow me to generate headers inside the engine source. I’m using 4.15.0 by the way.

UCLASS() is declared (and defined) in [FONT=Courier New]<UObject/ObjectMacros.h>