In my project, I need to include my class like below:
Player.h
#include "Tracer.h"
//...
Tracer.h
#include "Loader.h"
//...
Loader.h
#include "Player.h"
//...
Player.cpp
// Add Tracer as a scene component
// Some code here
Tracer.cpp
//Trace Actor By Channel
//part of the code
if (GetWorld()->LineTraceMultiByChannel(HitResultArray, TraceStart, TraceEnd, ECollisionChannel::ECC_GameTraceChannel1, CollisionQueryParams)) {
for (FHitResult hr : HitResultArray) {
/*Found Loader*/
if (hr.Actor->IsA(ALoader::StaticClass())) {
// Do something
}
}
}
Loader.cpp
void Loader::OverlapEnds(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
{
if (OtherActor->IsA(APlayer::StaticClass())) {
//Do something
}
}
However, this would cause recursive inclusion.
So, I try to add include guards to solve the problem.
But, I get an error “Error: UCLASS inside this preprocessor block will be skipped” if I add the include guards like below:
Tracer.h
#ifndef _LOADER_H_
#define _LOADER_H_
#include "Loader.h"
//...
#endif
How should I solve the recursive inclusion problem in UE4?