I made a basic button, when I press it it can turn on a light.
But I want this button to be able to trigger any blueprint, for exemple I want one button to trigger a light and an other button to trigger a door opening (with the same button blueprint)
Right now my only solution is to make two differents button blueprint with the exact same content except the custom event proper to each object, isn’t it possible to make some sort of global custom event ?
Look at this simple project i made for another topic: Dropbox - File Deleted
Esp look at how I used dispatchers.
For your problem best would be if you placed dispatcher either in player controller (or game instance), then everything that want to know about that event could hook into that dispatcher, and do its stuff.
But there is problem of coding same stuff over and over again. For that problem custom “blueprintable components” are solution. You create such component, make it hook to dispatcher in game instance. Then that component should check if partent actor has lights (or lights that have some tag set). Then modify those lights.
Or instead of tags and checking for components of parent actor, you could add blueprint interface and then check from component if parent has implemented interface.
All that stuff is done in my door sample project (all but components part).
You can give a button an unique property of what is being triggered. Like a string or a name and dispatch it with an event when a player interacts with the button. The event triggers only if a certain condition has been met. Think of it as a safe that has a security code.
I’d use a different approach than Event Dispatchers.
My approach would use Blueprint Communication.
Make a Blueprint inheriting from Actor and Call it “Triggerable” for example. (Abstract C++ class would be better for this though)
In this you define two Events, for example “Trigger” and “Antitrigger”(for turning off)
Now create a new Blueprint that is you concrete Actor. A Door For Example.
Override Trigger and Antitrigger the way you want (for example rotating for opening/closing)
Now create a new Bluprint called “TriggerButton” for example.
In this blueprint you create a Variable named “Triggerables” that is a type of Array of Triggerable
Expose it at spawn so you can pick multiple objects that need to be triggered.
Implement your usual “Button Press” etc. Logic. But loop through your Array of Triggerable and de/active them accordingly.