Download

How to subscribe/bind to an Event?

I already create event, but i dont know how to bind to the event
what i’ve done up until know :
Declare the event



public:
UCharacterState();

DECLARE_EVENT_OneParam(UCharacterState, FCharacterStateChangeEvent, ECharacterState);
FCharacterStateChangeEvent& OnChanged() { return CharacterStateChangeEvent; }

public:
FCharacterStateChangeEvent CharacterStateChangeEvent;


Broadcast the event:



void UCharacterState::ServerUpdateCharacterState_Implementation(ECharacterState _CharacterState)
{
    if (GetOwnerRole() == ROLE_Authority)
    {
        CharacterState = _CharacterState;
        CharacterStateChangeEvent.Broadcast(_CharacterState);
    }
}


what i still missing is how to subscribe/bind to the event

  • 个人笔记分享:单一代理范例:

  • class A: (forward) DECLARE_DELEGATE_OneParam(FOnHPChange, const TArray<float>&) //无前置标识宏!

  • class A: public: FOnHPChange OnHPChange; //无前置标识宏!

  • class A: Func_A() {
    if (OnHPChange.IsBound())
    {
    OnHPChange.Execute(TANoneCreaureHPCurrent);
    }

  • class B: Func_B()
    {

                      Inst A-&gt;OnHPChange.BindUObject(objectObject, &OBJ_CLASS::OBJ_FUNC);
                   }