Announcement

Collapse
No announcement yet.

How to subscribe/bind to an Event?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    Code:
    public:
    UCharacterState();
    
    DECLARE_EVENT_OneParam(UCharacterState, FCharacterStateChangeEvent, ECharacterState);
    FCharacterStateChangeEvent& OnChanged() { return CharacterStateChangeEvent; }
    
    public:
    FCharacterStateChangeEvent CharacterStateChangeEvent;
    Broadcast the event:
    Code:
    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

    #2
    • 个人笔记分享:单一代理范例:
      • 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->OnHPChange.BindUObject(objectObject, &OBJ_CLASS::OBJ_FUNC);
    }

    Comment

    Working...
    X