[UE5] TIL - 25 <UGameplayStatics::ApplyDamage, UDamageType>

ChangJin·2024년 4월 24일
0

Unreal Engine5

목록 보기
53/102
post-thumbnail

2024-04-24

깃허브!
https://github.com/ChangJin-Lee/ARproject
https://github.com/ChangJin-Lee/ToonTank

느낀점
ApplyDamage로 데미지를 적용시키는 방법을 학습했다. 함수로 Damage 관련된 내용이 구현되어 있는게 매우 신기했다. UDamageType에는 Damage에 관련된 아주 많은 내용을 담을 수 있었다.

TIL

  • UGameplayStatics::ApplyDamage
  • UDamageType

ApplyDamage

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/Kismet/UGameplayStatics/ApplyDamage?application_version=5.3


  • Hurts the specified actor with generic damage.
  • 특정 액터에 generic damage를 입힌다. 실제 데미지는 액터에 마지막에 적용이 된다.

  • 5개의 매개변수가 있다.

Parameters

NameDescription
DamagedActorActor that will be damaged.
BaseDamageThe base damage to apply.
EventInstigatorController that was responsible for causing this damage (e.g. player who shot the weapon)
DamageCauserActor that actually caused the damage (e.g. the grenade that exploded)
DamageTypeClassClass that describes the damage that was done.

  • 발사체 쪽에서 구현한다.
void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	
	AActor* MyOwner = GetOwner();
	
	if(MyOwner==nullptr)
	{
		Destroy();
		return;
	}

	AController* MyOwnerInstigator = MyOwner->GetInstigatorController();
	UClass* DamageTypeClass = UDamageType::StaticClass();

	if(OtherActor && OtherActor != this && OtherActor != MyOwner)
	{
		UGameplayStatics::ApplyDamage(OtherActor, Damage, MyOwnerInstigator, this, DamageTypeClass);
	}

	Destroy();
}


UDamageType


https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/UDamageType?application_version=5.3


  • A DamageType is intended to define and describe a particular form of damage and to provide an avenue for customizing responses to damage from various sources.
  • 다른 소스로부터 받은 데미지에 대한 정보를 저장하는 Class이다.

DamageType.h를 뜯어보면 다음과 같다.




class UDamageType : public UObject
{
	GENERATED_UCLASS_BODY()

	/** True if this damagetype is caused by the world (falling off level, into lava, etc). */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
	uint32 bCausedByWorld:1;

	/** True to scale imparted momentum by the receiving pawn's mass for pawns using character movement */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
	uint32 bScaleMomentumByMass:1;

	/** When applying radial impulses, whether to treat as impulse or velocity change. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = RigidBody)
	uint32 bRadialDamageVelChange : 1;

	/** The magnitude of impulse to apply to the Actors damaged by this type. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=RigidBody)
	float DamageImpulse;

	/** How large the impulse should be applied to destructible meshes */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Destruction)
	float DestructibleImpulse;

	/** How much the damage spreads on a destructible mesh */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Destruction)
	float DestructibleDamageSpreadScale;

	/** Damage fall-off for radius damage (exponent).  Default 1.0=linear, 2.0=square of distance, etc. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
	float DamageFalloff;
};

  • 예를들어 게임에서 DamageType_Fire를 데미지를 입은 액터쪽에서 붙일 수 있다.

  • UDamageType은 immutable data로 다루어져야한다. 그리고 static code functionality를 가져야한다.

  • Immutable data란 수정, 제거가 절대로 되어선 안되는 엄격하게 관리되는 데이터를 말한다.

  • Syntax
class UDamageType : public UObject  


profile
Unreal Engine 클라이언트 개발자

0개의 댓글