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.
class AArenaCharacter : public ACharacter
/** 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
/** Who hit us */
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?
Do you really have AArenaCharacter defined in ArenaCharacter.cpp file, as you have suggested? Any marked-up (i.e. UCLASS, USTRUCT etc.) types must be defined in a .h file of the same name as the type, but without the prefix - i.e. ArenaCharacter.h in your case - and in a Public, Private or Classes folder located underneath your module folder.
I figured it out. In the ShooterGame example in the ShooterGame.h they #include a header file called ShooterGameClasses.h this file contained a #include to every class in the project. Its is actually auto generated by the Unreal Engine. I looked in my project and found I too have a MyProjectClasses.h however mine was empty. You can’t add anything to that file since it is auto generated and will delete anything you add to it. I instead added all the includes into MyProject.h then I simple #include MyProject.h for every classes. This will insure no circular dependencies are created even when two classes refence each other.