Can anyone help me understand how this works? I am trying to implement the LastTakeHitInfo feature in my game. I was looking at the ShooterGame example to see how they did it. I am running into a circular dependency issue and I am not sure why the Shoot Game works and mine doesn’t.
ArenaCharacter.cpp
#include "ArenaTypes.h"
#include "ArenaDamageType.h"
#include "GameFramework/Character.h"
#include "ArenaCharacter.generated.h"
UCLASS(Abstract)
class AArenaCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
(...)
/** Replicate where this pawn was last hit and damaged */
UPROPERTY(Transient, ReplicatedUsing = OnRep_LastTakeHitInfo)
struct FTakeHitInfo LastTakeHitInfo;
(...)
}
Because ArenaCharacter implements “struct FTakeHitInfo LastTakeHitInfo” it needs to include #include “ArenaTypes.h”. There is a problem though
ArenaTypes.h
#include "Object.h"
#include "ArenaCharacter.h"
#include "GameFramework/DamageType.h"
#include "ArenaTypes.generated.h"
#pragma once
USTRUCT()
struct FTakeHitInfo
{
GENERATED_USTRUCT_BODY()
(...)
/** Who hit us */
UPROPERTY()
TWeakObjectPtr<class AArenaCharacter> PawnInstigator;
(...)
}
The pawn investigator needs to know about AArenaCharacter. If I don’t include #include “ArenaCharacter.h” I get the error: TWeakObjectPtr can only be constructed with Object types. But obviously when I add #include “ArenaCharacter.h” header it creates a circular dependency. This is how the Shoot game works. What am I missing?