관리 메뉴

Mini

[UE5] GE태그 방송하기 , 람다함수 본문

UE5/GameplayTags

[UE5] GE태그 방송하기 , 람다함수

Mini_96 2024. 6. 3. 22:04

0. ASC에서 방송하고, 위젯컨트롤러에서 구독함.

 

1. UAuraAbilitySystemComponent 에서 람다함수 선언, 변수생성, 방송(이펙트 실행시)

DECLARE_MULTICAST_DELEGATE_OneParam(FEffectAssetTags, const FGameplayTagContainer& /*AssetTags*/);
FEffectAssetTags EffectAssetTags; //구독, 방송에 모두쓰일 변수
void UAuraAbilitySystemComponent::EffectApplied(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);
}

 

2. OverlayWidgetController에서 구독

멤버함수를 만드는 대신, 람다함수를 사용해보자.i) ASC를 내가만든 ASC로 캐스팅하고, 구독(Add)함ii) 작동확인을 위해 로그만 찍어봄

void UOverlayWidgetController::BindCallbacksToDependencies()
{
	...

	Cast<UAuraAbilitySystemComponent>(AbilitySystemComponent)->EffectAssetTags.AddLambda(
		[](const FGameplayTagContainer& AssetTags)
		{
			for (const FGameplayTag& Tag : AssetTags)
			{
				const FString Msg = FString::Printf(TEXT("GE Tag: %s"), *Tag.ToString());
				GEngine->AddOnScreenDebugMessage(-1, 8.f, FColor::Blue, Msg);
			}
		}
	);
	
}

 

3. 결과 : 정상작동,

위젯컨트롤러에서 GE태그를 사용할수 있게됨!