Widgets and Casting to Widget

Hey Guys

Have a fairly quick question regarding widgets.

I currently have a main Inventory Widget, and in this widget, Slot Widgets are generated for the amount of inventory slots I have. These Slot Widgets are created when the Main Inventory Window widget is constructed.

What I would like to know, is when I click on the Slot Widget, how can I have it interact with an element in the Main Inventory Window as from the Slot widget, there is no reference to the Main Inventory widget.

I guess I could use ‘Get All Widgets of Class’ to cast to the Main Inventory Widget upon mouse down, but not sure how costly this is.

The reason I am looking at doing this is rather than use bindings in the Main Inventory Window, I can just update things when I click on a Slot as they don’t need to be constantly updating.

Thanks

Each slot can have an *exposed on spawn *Main Inventory Window reference, which the blueprint that created them sets; in this case the Main Inventory Window itself - that’s direct communication via a hard reference, far from ideal but ok. So each slot knows what spawned it and can talk back to its creator. [HR][/HR]
What’s much better here is a simple event dispatcher in the slot.

  • slot has an even dispatcher that sends self reference when clicked on (or any other data)
  • when Main Inventory Window creates slots, it registers a custom event with the slots’ dispatchers

So in practice, you have an *onClicked *in the slot executing its own dispatcher which triggers an event in the Main Inventory Window - this event will have the data from the slot. Any registered slot can tell the Main Inventory Window it has just been interacted with.

Yup, perfect for this and many other things; especially useful for things created dynamically on the fly.

Wow, I didn’t even think of using Event Dispatchers. Thanks Everynone, I think this should solve my problem. All I basically wanted to do was that when I click on a Slot, it updates and image or some text in the main inventory window.

Thanks for the idea, should do the trick nicely.