In an empty level i have an Actor Blue Print “BP_light” with a point light component that i would like to turn on and off from a widget that is displayed in the level, not on the character in any way (i.e. a computer screen).
I have placed (3) instances of BP_Light in the level, let’s call them BP_Light1, BP_Light2, and BP_Light3
I created a widget “WBP_LightControl” with (3) buttons on it with the intention of each button toggling one specific light on and off and added it as a component to an Actor Blue Print called “BP_LightControl”. I placed BP_LightControl in the level.
I can not, for the life of me, get the WBP_LightControl to send any info to the BP_Light instances in the level. I’ve searched for about a day now and came across a few methods but they don’t address communicating from a widget that is not attached to the player character to an individual instanced actor in the level. And they all seems clunky to me and not scale-able.
I’m trying to learn how to get button_1 in WBP_LightControl to toggle BP_Light1; button_2 to toggle BP_Light2; and button_3 to toggle BP_Light3.
I feel like i’m missing something because every tutorial or forum post regarding this that I’ve come across suggest casting to the source of the interaction which ends up being the player character in the examples. But casting seems a bit heavy just for a light switch. (Unless i’m mistaken)
In all intents and purposes i’m trying to make a series of light switches that only affect one light each.
Can someone help point me in the right direction?
I hope i explained my issue well enough, Thank you!
Casting isn’t that bad if it is one-time things like this. Unless you think your players are super-human and can somehow press the button 100 times per tick, you are fine using casting.
If you don’t want to use casting there are also event dispatchers and get all actors with tag nodes. Those might also be considered “heavy” if cast is considered “heavy,” though. I think any method you chose should be perfectly fine in this case.
In your BP_LightControl you can create 3 variables “Light1”, “Light2”, “Light3” that you can mark as “expose on spawn”. When you placed BP_LightControl into the level you can pick your light actors from within the details panel of BP_LightControl. You now have a reference of your lights inside of your BP_LightControl and can either pass them directly to the widget or use event dispatchers inside your widget that you bind to from within your control BP.
Thank you, this works pretty well for a single pairing of controller and light(s) and helps solve another issue i was looking at. Exposing the variables and being able to get a reference to an actor like that is pretty useful. I’d ultimately like to make the BP “modular” in such a way that i can set down the controller in a level and connect it to a light or lights and operate as one would expect, regardless of how many there are in the level.
However, it still falls short of one of my requirements. I’m not able to put down more than one BP_LightControl and use them to control separate sets of lights as it seems to always reference the same light, even when the exposed BP_Light object variables are changed in the second controller that’s placed in the level.
My guess is i don’t quite understand how instancing and inheritance work with these actor blueprints.
I’ll try and post some pictures after work but the BPs have gotten a bit messy with me fussing around with different attempts to get it to work lol.
I’ve messed around a tiny bit with casting and the event dispatcher and i think ultimately that will meet my requirements. Thanks for helping to clarify the use case for casting, i was under the assumption that it would not be efficient for something so simple.