176. Dealing Damage To Actors

if (bSuccess)
	{

		FVector ShotDirection = -Rotation.Vector();
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactEffect, Hit.Location, ShotDirection.Rotation());

		AActor* HitActor = Hit.GetActor();	
		if (HitActor != nullptr) 
		{
			FPointDamageEvent DamageEvent(Damage, Hit, ShotDirection, nullptr);
      
            HitActor->TakeDamage(Damage, DamageEvent, OwnerController, this);
		}
	}

[1/1] Compile [x64] Gun.cpp
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(60): error C2079: ‘DamageEvent’?(?? ??? struct ‘FPointDamageEvent’?(??) ???ϴ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(60): error C2440: ‘??? ?’: ‘initializer list’??? ‘int’(?)???ȯ? ???ϴ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(60): note: ??ϼȶ??? ?ʹ? ???ϴ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(62): error C2664: ‘float AActor::TakeDamage(float,const FDamageEvent &,AController *,AActor *)’: ???2?(??) ‘int’??? ‘const FDamageEvent &’(?)???ȯ? ???ϴ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(62): note: ??? ‘int’??? ‘const FDamageEvent’(?)???ȯ? ???ϴ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(62): note: ??? ???‘FDamageEvent’?(??) ???ϴ?
D:\UE_5.3\Engine\Source\Runtime\Engine\Classes\GameFramework\Actor.h(3375): note: ‘FDamageEvent’ ??? ???ʽÿ?
D:\UE_5.3\Engine\Source\Runtime\Engine\Classes\GameFramework\Actor.h(3375): note: ‘AActor::TakeDamage’ ??? ???ʽÿ?
D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\Gun.cpp(62): note: ??? ‘(float, int, AController *, AGun *)’?(??) ?ġ???
Total time in Parallel executor: 9.00 seconds
Total execution time: 10.60 seconds
Build failed.

I saw someone left a message in the lecture.

If you are using Unreal Engine 5.1 or later, you should include #include “Engine/DamageEvents.h”.

Since I include the header file, there is no error anymore.

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

Privacy & Terms