Announcement

Collapse
No announcement yet.

Multiple Objects sharing the same Custom Event

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

    Multiple Objects sharing the same Custom Event

    Hi!

    In my UI, I create multiple sub widgets forming like a grid. The sub widget has an event dispatcher say SomethingChanged. In the main UI, while creating the sub widgets I bind the same "Custom Event" to each of them. When SomethingChanged fired on one of the widgets for the first time, everything is fine. But when the event occurs on another widget of the same type, the custom event is not called. The idea is one Custom Event for multiple objects of same type. What is the workaround for this?

    Thanks.

    #2
    A few more details on how'd you set it up would be nice. Do each of the widgets fire the event dispatch when "something changes"?

    I think youd want to have the event trigger a level above each individual widget to stop them from all each dispatching the same event at the same time. Just have listeners active on each of them, and have the dispatcher somewhere else to ensure you dont get fighting between dispatches?
    Need another dev on your UE4 project? Send me a shoutout and I'll lend a hand

    Comment


      #3
      Dispatchers are for situation when one blueprint needs to notify many bleuprints.
      I am not getting if (in your project) all of them bind to same dispatcher in owner blueprint or if owner blueprint binds to that dispatcher in all of child blueprints.
      Because if its second case, you just change binding to latest one, unbinding previous ones.

      If there is event that you need propagate from one child widget to all of them, do it in 2 steps:
      - make custom event in parent/owner widget,
      - when you need to call that global event for all child widgets: cast to owner wiget, call its custom event
      - from that custom event call dispatcher that sends event to all who is hooked to it
      - when creating child widgets hoot to dispatcher >IN parent< widget (not the other way around)

      Or use interfaces:
      create interface that has 1 function, create that "custom event function" in it.
      here it gets a bit weird (like always with interfaces).
      add that interface to all child widgets and to parent widget.
      in parent widget inside interface function do " "get all widgets with interface"
      in that loop cast to interface, do "interface call" pin needs to be YELLOW, this way you call all widgets that have interface
      now in child widget interface function do whatever you want for that event.

      How to trigger interface function:
      - either from parent, just call its interface function (this time as message).
      - or do same from child widgets: get reference to parent , cast to interface do interface call of parents function.

      Yes interfaces are bit counter intuitive here, so add a lots of comments.
      You have 2 different function: one interface function that is in child widget, one interface function that is in parent widget.
      To start everything you call parents interface function (for eg from some event that happened in one of child widgets)
      That parent interface function calls then all child interface functions in loop.

      Beauty of interfaces is that child widgets do not need to be of same class, and there are no ugly red wires.
      Last edited by Nawrot; 02-02-2016, 12:43 PM.

      Comment


        #4
        Well I fixed by calling a function on parent widget. The behavior is wierd for me, I thought the event dispatcher was a callback.

        Comment

        Working...
        X