I often make a class with many functions/methods inside. The problem is, even if class definition in header file can be relatively small (<100 lines), associated .cpp file can be huge (>500 lines). In normal projects I often split function definitions into many smaller .cpp files. Apparently, I can’t do it in Unreal Engine cpp projects. I guess the problem is that I need to convince somehow Makefile (Build.cs file to be specific) that it needs also to build added another .cpp file. How can I do that?
Example:
(MyActorA.h file)
#include "GameFramework/Actor.h"
#include "MyActorA.generated.h"
UCLASS()
class MYPROJECT_API AMyActorA : public AActor
{
GENERATED_BODY()
public:
AMyActorA();
void BeginPlay();
void Tick(float DeltaTime);
void functionA();
};
(MyActorA.cpp)
#include "MyProject.h"
#include "MyClass.h"
#include "MyActorA.h"
AMyActorA::AMyActorA() {
MyClass *x = new MyClass;
}
void AMyActorA::Tick(float DeltaTime) {
functionA();
}
void AMyActorA::BeginPlay() {
}
Now - when I make void AMyActorA::functionA()
definition inside AMyActorA.cpp file or similar AMyActorB.cpp file, everything works. I could of course create auxiliary files with empty actors, but I rather would not choose this option, since it wouldn’t really help in organising files. Suppose I created some empty, non-inheriting class in UnrealEngine, like MyClass.h. If I create additional file, like Source.cpp and put definition of MyClass constructor here, I can call it from AMyActorA class (like showed in example above). But, when I put void AMyActorA::functionA()
in Source.cpp instead of MyActorA.cpp file, like this:
#include "MyClass.h"
#include "MyActorA.h"
MyClass::MyClass() {
}
void AMyActorA::functionA() {
}
I get the following error:
Severity Code Description File Project Line Suppression State
Error LNK2019 unresolved external symbol "public: void __cdecl AMyActorA::functionA(void)" (?functionA@AMyActorA@@QEAAXXZ) referenced in function "public: virtual void __cdecl AMyActorA::Tick(float)" (?Tick@AMyActorA@@UEAAXM@Z) C:\UE4 Projects\MyProject\Intermediate\ProjectFiles\MyActorA.cpp.obj MyProject 1