관리 메뉴

Mini

[UE5] PC 리팩토링, 클라에서 포션먹음 메시지 안뜨는 버그수정, 클라이언트 RPC 본문

UE5/Gameplay Abilities

[UE5] PC 리팩토링, 클라에서 포션먹음 메시지 안뜨는 버그수정, 클라이언트 RPC

Mini_96 2024. 6. 9. 19:11

* FResultHit CursorHit을 맴버변수로두고, 재사용하기로함

void CursorTrace();
TScriptInterface<IEnemyInterface> LastActor; //가장최근에 가리킨 적
TScriptInterface<IEnemyInterface> ThisActor; //현재커서위치가 가리키는 적
FHitResult CursorHit;

 

-기존

FHitResult Hit;
if(GetHitResultUnderCursor(ECC_Visibility,false,Hit))
{
    CachedDestination = Hit.ImpactPoint; //커서눌린위치를 저장
}

-리팩토링

if(CursorHit.bBlockingHit)
{
    CachedDestination = CursorHit.ImpactPoint; //커서눌린위치를 저장
}

 

 

*  클라에서 포션먹음 메시지 안뜨는 버그수정

-원인 : ASC > EffectApplied 가 서버에서만 콜되고 있어서임 / 즉, 클라로 복제가 안됬음

생성자에서 델리게이트 하고있음

void UAuraAbilitySystemComponent::AbilityActorInfoSet()
{
    OnGameplayEffectAppliedDelegateToSelf.AddUObject(this,&UAuraAbilitySystemComponent::EffectApplied);
    
}

델리게이트 설명이 서버에서 콜 된다고함

/** Called on server whenever a GE is applied to self. This includes instant and duration based GEs. */
FOnGameplayEffectAppliedDelegate OnGameplayEffectAppliedDelegateToSelf;

- 해결 :

* 클라이언트 RPC : 서버에서 실행되고, 클라에 복제해줘

ufunction안에 client옵션을넣고, 함수명앞에 Client붙이는계 관례다.

UFUNCTION(Client,Reliable) //클라이언트 RPC, 신뢰성(패킷이 손실되도 클라에 도착보장)
void ClientEffectApplied(UAbilitySystemComponent* AbilitySystemComponent, const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle);

구현부뒤에 함수명_Implementation 붙여야함

void UAuraAbilitySystemComponent::ClientEffectApplied_Implementation(UAbilitySystemComponent* AbilitySystemComponent,
                                                const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle)
{
    FGameplayTagContainer TagContainer;
    EffectSpec.GetAllAssetTags(TagContainer); ///** Appends all tags that apply to this gameplay effect spec */
    EffectAssetTags.Broadcast(TagContainer);
}

그 함수로 델리게이트 교체

void UAuraAbilitySystemComponent::AbilityActorInfoSet()
{
    OnGameplayEffectAppliedDelegateToSelf.AddUObject(this,&UAuraAbilitySystemComponent::ClientEffectApplied);
    
}

결과 : 클라에서도 메시지 잘 뜨는모습