Send a message without casting.
So, I'm creating a widget that I can toss into a slew of different menus (that are widgets themselves) that selects a player 1-4. I'd like to have it call a function/event or what have you that tells its parent a player has been selected and gives the player number.
I know with the custom events, I have to get reference to the object, and cast it to the correct type. The problem I'm having is that widgets can't inherit from other widgets, and I have several different menus that can all be individually showing different players, so I'd have to go to each menu one by one, cast it into one of the menu types, and if it succeeds, tell it the player's been selected. I'd rather avoid doing that since every time I make a new menu, I'd have to add it to the list of possible casting types.
Event Dispatchers are no good because I still have to cast it to the correct type to get reference to the event I want called (or I simply don't understand event dispatchers).
Blueprint Interfaces have the same problem, you have to cast it to the correct type. I just want to basically send a message to an object that says, "Hey, this player was selected, do stuff with it."
I want to be able to simply drop it into a widget, it automatically finds its parent and tells it when a player is selected and which player it is.
I'm wondering if there's a way to send a message like that, or am I wasting my time looking for a way around it?
Blueprint Interfaces exist so that you don't have to cast to a type before sending a message. I think you may be mistaken there.
Once a class implements a specific interface function, you could ALSO cast an object to the class and call the function directly, but you can send an interface message to any object that I'm aware of, and if the object doesn't implement the interface then nothing will get called on it.
You may need to unclick the "Context Sensitive [ ]" checkbox to see the interface call option in your blueprint action menu.
I haven't used it with widgets myself, yet, but it worked well for me with some actors I was dealing with that didn't have a common subclass.
Follow this question
Once you sign in you will be able to subscribe for any updates here