BP/Native 모두에서 Delegate를 사용하고 싶을 때

전지훈·2021년 8월 16일
0

Unreal

목록 보기
7/25
post-thumbnail
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnInventoryItemChanged, bool, bAdded, URPGItem*, Item);
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnInventoryItemChangedNative, bool, URPGItem*);
/** Delegate called when an inventory item has been added or removed */
UPROPERTY(BlueprintAssignable, Category = Inventory)
FOnInventoryItemChanged OnInventoryItemChanged;

/** Native version above, called before BP delegate */
FOnInventoryItemChangedNative OnInventoryItemChangedNative;
void ARPGPlayerControllerBase::NotifyInventoryItemChanged(bool bAdded, URPGItem* Item)
{
	// Notify native before blueprint
	OnInventoryItemChangedNative.Broadcast(bAdded, Item);
	OnInventoryItemChanged.Broadcast(bAdded, Item);

	// Call BP update event
	InventoryItemChanged(bAdded, Item);
}

그냥 MULTICAST_DELEGATE는 블루프린트에서 사용할 수 없기 때문에 DYNAMIC_MULTICAST_DELEGATE를 사용한 것을 볼 수 있다.

BP/Native 모두 델리게이트를 호출한다면 이와 같이 구성하는 것이 가장 바람직한 코드로 생각된다.

profile
10%의 확신과 90%의 어.. 이게 왜 되지?

0개의 댓글