inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

이득우의 언리얼 프로그래밍 Part2 - 언리얼 게임 프레임웍의 이해

8강 아이템 시스템

delegate wrapper 사용 이유

426

coseunghoding

작성한 질문수 6

0

안녕하세요 좋은 강의 정말 감사드립니다.

다름이 아니라 delegate wrapper 사용 이유가 궁금하여 질문 드립니다.

선생님께서 delegate를 다수 배열로 관리하기 해야 하는데 이 자체를 인자로 쓸 수 없다고 하신 부분이 잘 이해가 되지가 않습니다. 어느 부분을 인자로 쓸 수 없는지에 대해 구체적으로 말씀해주실 수 있나요?

FTakeItemDelegateWrapper 랩퍼 구조체가 아닌 FOnTakeItemDelegate 델리게이트를 TArray 배열에 넣을 수도 있고

이런 식으로 바인드도 되고, 실행도 되는데 왜 델리게이트 랩퍼 구조체를 따로 만들어야하는지가 궁금합니다.

unreal-engine ue-blueprint 언리얼-c++

답변 2

0

이득우

안녕하세요.

FOnTakeItemDelegate 선언은 아래 그대로 사용하셨는지요?

DECLARE_DELEGATE_OneParam(FOnTakeItemDelegate, class UABItemData* /*InItemData*/);

그리고 헤더에서 TakeItemActions2를 어떻게 선언했는지 볼 수 있을까요?

 

0

coseunghoding

답변 감사드립니다.

image제가 실수로 이렇게 선언해서 TakeItemActions2에 UPROPERTY를 적용하지 않아 생긴 문제였습니다. TakeItemActions2에 UPROPERTY를 붙이니 바로 오류가 뜨네요!

 

그렇다면 UPROPERTY 배열에 델리게이트를 넣을 수 없어 랩퍼 구조체에 델리게이트를 넣고 해당 구조체를 UPROPERTY 배열에 넣어주는 것은 이해했는데, 델리게이트 배열에 UPROPERTY를 붙인 이유를 잘 모르겠습니다. 블루 프린트에서 사용하기 위한 목적인가요?

1

이득우

말씀하신대로 Part2 예제처럼 로컬의 C++에서만 사용한다면 상관 없겠지만, 이런 저런 확장까지 감안했을 때 아무래도 UPROPERTY화 시키는게 좋겠지요.

0

coseunghoding

명확하게 이해했습니다. 답변 감사합니다!

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.

님의 질문에 대해 답변드리겠습니다.

Delegate wrapper를 사용하는 주된 이유 중 하나는 delegate의 직렬화와 관련된 제약 때문일 수 있습니다. Unreal Engine에서는 게임의 상태를 저장하거나 네트워크를 통해 데이터를 전송할 때 객체의 상태를 직렬화하는 과정이 필요합니다. 그런데, 일반적인 delegate는 직렬화를 지원하지 않아, 게임의 상태 저장이나 네트워크를 통한 상태 공유시에 delegate에 바인딩된 정보를 유지하기 어려울 수 있습니다. 이런 문제를 해결하기 위해 delegate를 감싸는 wrapper 구조체를 사용하면, 구조체를 통해 직렬화를 지원하게 만들어, delegate의 상태를 보다 쉽게 관리할 수 있습니다.

또한, 다수의 delegate를 배열로 관리할 때, 각기 다른 타입의 delegate를 하나의 배열에 저장하고자 할 때 type safety와 관련된 문제를 해결하는 데에도 wrapper 구조체가 유용할 수 있습니다. 각 delegate에 대한 wrapper 구조체를 정의하면, 다양한 형태의 delegate를 안전하게 관리하고, 실행 시 타입 체크를 통해 오류를 줄일 수 있습니다.

사진의 코드를 보면, TakeItemActions 객체에 여러 종류의 액션을 추가하는 과정에서 delegate를 사용하고 있습니다. 여기서 FTakeItemDelegateWrapper 랩퍼 구조체를 사용하는 경우, 이러한 delegate의 집합을 더 유연하게 관리할 수 있으며, 추가적으로 직렬화 지원이나 타입 안정성을 강화하는 역할을 할 수 있습니다. 따라서 이러한 이유로 wrapper 구조체를 별도로 만들어 사용하는 것은 delegate를 폭넓게 활용하기 위한 Unreal Engine 프로그래밍의 한 방식이 될 수 있습니다.

The image shows lines of code, specifically from a programming language that appears to be C++ based on the syntax. The code snippet involves operations on a `TakeItemActions` object, with the `Add()` method being called multiple times to add different action delegates. These delegates seem to be specifying actions such as `EquipWeapon`, `DrinkPotion`, and `ReadScroll` for a character class named `AABCharacterBase`. The syntax indicates that the actions are related to a gameplay mechanics, likely for a video game where a character can perform various actions like equipping a weapon, drinking a potion, or reading a scroll. Each line is creating a delegate that binds a function to an action that can be taken by the character.
The image shows a snippet of source code, possibly from a computer program written in C++. Here is a description of the contents:- The snippet defines a function named `TakeItem` which is a member of a class with the name `AABCharacterBase`. This function takes a single parameter, a pointer to `UABItemData` named `InItemData`.
- Inside the `TakeItem` function, there is an `if` statement that checks if `InItemData` is not null (i.e., it contains a valid address).
- Within the `if` block, there are two function calls:
  - The first function call `TakeItemActions1` casts an integer value (`uint8`, which is an unsigned 8-bit integer) obtained by accessing the `Type` member of the `InItemData` object, then calls `ItemDelegate.ExecuteIfBound` with `InItemData` as an argument.
  - The second function call `TakeItemActions2` does basically the same thing but presumably performs a different set of actions as suggested by the “2” in its name.This code is utilizing some features of C++ like classes, pointers, type casting (to `uint8`), member access (`->`), and possibly delegation patterns (`ItemDelegate.ExecuteIfBound`). However, the code snippet is lacking context, such as the include directives, the definition of `UABItemData`, and what `TakeItemActions1` and `TakeItemActions2` functions actually do, so the exact behavior and purpose of the function in the broader application is not clear.

무한맵 제작과정중에 GetWorld 가 Nullptr 을 반환합니다.

0

46

2

12강 행동트리에서 질문이 있습니다.

0

52

1

위젯 사이즈랑 위치 질문드려요.

0

81

3

행동트리의 데코레이션 관련하여 질문이 있습니다.

0

94

3

VS 2026 의 문제일까요?

0

488

2

에셋참조 블루프린트질문

0

67

2

애님 몽타주 콤보 관련질문

0

70

2

ThirdPerson CDO 에러가 생깁니다.

0

95

3

캐릭터가 움직이지 않습니다.

0

181

4

쿠킹 폴더 지정시 , Item 이외에는 지정하지 않는지 궁금합니다.

0

62

2

TSoftObjectPtr 를 사용했음에도, 메모리에 로드 됩니다.

0

94

2

7강에 나오는 생성자에 대해서 궁금합니다.

0

78

2

6강을 마무리하며 트레이스 채널 을 이해하지 못했습니다.

0

73

2

3강을 마무리 하며, 카메라가 움직이지 않습니다.

0

71

2

Use Controller Rotation 옵션값이 궁금합니다.

0

83

2

3강 입력 시스템 적용 중, 5.6 버전은 입력 매팅이 2개 입니다.

0

64

2

PlayerController 에 대헤 제가 잘못 이해한 것 같습니다.

0

78

2

13강 UpdateStat 부분에서 문제를 겪고 있습니다.

0

63

2

BP_PlayerController의 CustomEvent노드 이유가 궁금합니다.

0

64

1

콤포넌트 포인터 선언시 TObjectPtr<>과 UStaticMeshComponent* 차이점

0

72

2

CharacterMovementComponent의 RotationRate관련해서 질문이 있습니다.

0

114

2

언리얼 공부방법에 대해 질문드립니다.

0

87

2

4강 에서 이상한 그림자가 남습니다.

0

46

1

2강에서 카메라 회전안되시는분 참고

2

91

2