Incomplete class type FDamageEvent is not allowed

I’m having issues implementing my TakeDamage function override for my character class. The “DamageEvent” struct won’t allow me to call it’s “GetBestHitInfo” public function to gather data on HitResult and HitDirection.

The error I’m getting is “Incomplete class type FDamageEvent is not allowed”.

I have Pawn.h, Actor.h, and even EngineTypes.h but my code still won’t compile for the use of an undefined type.

Here’s a snippet of my Character.h:

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Engine/EngineTypes.h"
#include "GameFramework/Actor.h"
#include "MainCharacter.generated.h"

protected:
virtual float TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;

Here’s a snippet of my Character.cpp:

#include "MainCharacter.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/Actor.h"
#include "Engine/EngineTypes.h"

float AMainCharacter::TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
	FHitResult HitResult{};
	FVector HitDirection{};

	DamageEvent.GetBestHitInfo(this, DamageCauser, HitResult, HitDirection);

return 0.0f;
}

Any ideas what’s going on?

Remove struct keyword from the signature.

You can forward-declare the struct in .h to avoid including additional headers, but you have to do forward-declarations outside of the class declaration, otherwise you are declaring it within its namespace and it’s treated as a new type, eg. AMainCharacter::FDamageEvent instead of just FDamageEvent.

#include "MainCharacter.generated.h"

struct FDamageEvent;

class AMainCharacter : public ACharacter
{
    virtual float TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
};
#include "Engine/EngineTypes.h"

float AMainCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
}

Hey Chatouille, thanks for the reply.

I forward declared the struct outside of the class but I’m still getting the same error.

This doesn’t make sense because anywhere else in my code, Intellisense recognizes FDamageEvent as a struct so I would think that it’s not an incomplete type, unless I’m not fully understanding how Intellisense works.

Do you think it has something to do with how I’m using DamageEvent in my code?

float AMainCharacter::TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
	FHitResult HitResult{};
	FVector HitDirection{};

	error is here---> DamageEvent.GetBestHitInfo(this, DamageCauser, HitResult, HitDirection);

return 0.0f;
}

My compiler also shows these two errors if this helps:

1>D:\Game Development\Unreal Projects\Siege\Source\Siege\Character\MainCharacter\MainCharacter.cpp(394): error C2027: use of undefined type ‘FDamageEvent’

1>C:\Program Files\Epic Games\UE_5.1\Engine\Source\Runtime\Engine\Classes\GameFramework\Actor.h(3230): note: see declaration of ‘FDamageEvent’

So I found that if I remove the

IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;

line from my Editor.Target.cs it removes the error. I only added this due to a compiler recommendation since I converted my project from UE5 to UE5.1

Any ideas why this would happen? Here’s the entire code:

using UnrealBuildTool;
using System.Collections.Generic;

public class GameEditorTarget : TargetRules
{
	public GameEditorTarget( TargetInfo Target) : base(Target)
	{
		Type = TargetType.Editor;
		DefaultBuildSettings = BuildSettingsVersion.V2;
		IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
        ExtraModuleNames.AddRange( new string[] { "Game" } );
	}
}
1 Like

I found that just including “Engine/DamageEvents.h” fixed a similar compile error for me (having also just adding the recommended Editor.Target.cs line myself).

1 Like

Thanks for this.

I also found the same issue for FOverlapInfo whose header is “Engine/OverlapInfo.h” in case anyone runs into the same issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.