… effectively creates some glue that makes your class work with the UObject sub-system. Part of that glue is the declaration of a class constructor, and it is required that you implement it in your module. If your class has a lot of methods, you probably already have a separate .cpp file just for that class, and you can add the constructor definition to that file. If your class doesn’t have any code, or all code is inlined, then you can just throw it into any other .cpp file. Typically I use the MyModule.cpp for that, or if I have many classes with no code I add MyModuleClasses.cpp and put the constructors in there (for example, take a look at SettingsClasses.cpp).
The format for the constructor definition is as follows:
UMyCoolClass::UMyCoolClass( const class FPostConstructInitializeProperties& PCIP )
: Super(PCIP)
{
/* do object initialization in here, if needed, otherwise leave empty */
}
Note that UObjects (and therefore AActors as well) have their properties initialized from the INI file, or set to 0/nullptr if no settings are specified. You cannot pass any additional arguments into the constructors but will have to defer all run-time initialization to subsequent method calls or property assignments after creating the object. It seems like a limitation at first, but it opens up some interesting possibilities. For example, all UObjects and actors have the same constructor API, which means that they can be easily created automatically by other means, i.e. from the Blueprint system or when they’re replicated over the network. The only thing you have to provide is a class name.
If custom constructor arguments were allowed then we would have to provide a mechanism to generate constructor calls and populate them with valid arguments automatically at run-time. Probably the only elegant way to do this would be a dependency injection framework, which is quite difficult to create and use in C++. In other similar languages, such as C# this may be a little bit easier, but note that even there most frameworks do not allow custom constructor arguments for serializable objects.
‘Action’ : ‘class’ type redefinition
‘ActionEnums::ActionType’ : ‘enum’ type redefinition
‘CurrentActionType’ : undeclared identifier
‘Action’ : base class undefined
The header file is probably getting included more than once. You want this at the top of every .h:
#pragma once
The file layout of C++ is a little tricky, and UE4 projects can make that more complicated with generated headers. You may want to experiment a bit with a simple Win32 Console Application before writing any serious code.