Download

Light don't turn on after repairing the electrical panel

Hello all !
I might be a bit dumb-dumb, but I’m a bit stuck with my thing. I explain, there’s an electric board that is broken in my game. The player have to find tools, then get back and interact with it to repair it, and when it’s done, a light close to it turn on.
So, in my electric board blueprint, I just ask if the player have the tools when he interact. If yes, I put a bool variable to 1 (all my variables are in my third person character blueprint). And in my light bp, with the event begin play, I ask if the bool variable from earlier is true, and if it is, I toggle the visibility. In my head, it should work, but sadly my head isn’t Unreal x) So, if a good man can explain to me where I’m wrong ^^ The thing with the tool work, as the string appear if I have the tools, and if I’ve not, the other one appear.
Electric board BP :

](filedata/fetch?id=1817279&d=1601487784)
Light BP :
](filedata/fetch?id=1817280&d=1601487796)

Event BeginPlay is called once when the object is spawned into the world. Using it to check a bool variable would work if you were spawning the object after you set the bool variable.

There are several ways to make this work: interface to pass the bool variable between blueprints, event dispatchers, or direct blueprint communication with casting, which is what you are using.

For direct blueprint communication you can solve it like this:

Spawn the light after you set it to be fixed in the interact event on the electric board bp.

or

Add a custom event to the light BP. In the event set the point light to toggle visibility.

Create another custom event in the character BP. Set this event up to check if the player has tools are not. If true call the event from the light BP to toggle visibility on.

Setup your interact event on the electric board to call the custom event on the character BP.

Here is some documentation to help as well:

Direct Blueprint Communication:

Event Dispatchers:

Interfaces:

Events:

Thanks, it works ! But for one light, not more than one. I tried with the custom events, and to call the event for the point light, I tried with a “Get actor of class”. I tried first with a “Cast to [name of my blueprint with the pointlight]”, but my problem is that I usually doesn’t know what to put in the object of the cast, as there’s nothing like “Other actor” or else, like there’s on actor begin overlap, for example, on the custom event… I saw that there was “Get all actors of class”, but it have an array. I created a variable as a reference of my pointlight, and put it in array, but it seem it doesn’t see it when I try to plug it in the get all actors…
The light BP :


The character BP :

The electric board BP :

You have the right idea but the implementation is slightly off. Unfortunately Get All Actors Of Class can be a pain to use. There are many methods that work, but here is one I use often.

Go to your light bp add an integer variable name is LightID or something similar, set it to expose on spawn and be instance editable. This will allow you to manually set the ID of each light BP in your level. Don’t set the variable in the blueprint editor, set it in the level scene under the details panel when the actor is selected. That will make sure that is the only actor that has that ID.

Setup two custom event like so in your character BP:

This will allow you to find the light BPs with the unique ID you set in the world and create a reference to it. From there you can toggle it freely. To make sure the order of events works properly here are the other BPs for you to give you an idea:

LightBP is simple, a point light and an integer variable, no code. In the scene I set LightID to 5.

ToolsBP is a simple box collision, the particle system was added only so I could see where it was. It sets the boolean to true on the player character and grabs the light reference and stores it for easy use.

ElectricBoardBP a simple box collision that checks to see if the player HasTools? boolean is true, if so it turns the light on or off.

This is a very basic implementation that works on my end, most game ready solutions will be a bit more complex. Hope this helps.

Hmmm, it seem to not work with x) It’s still activate only one light. The “Light to activate” node, is it a reference to BP_Light ? The only difference I have is that I put 1 in the ==, for the ID (and I’ve put 1 in the ID for each lights after selecting them in the scene).

Well, I fixed it, and I was a bit dumb. I did before that a bit the same thing, but for a switch turning on multiple lights, but it was in the level blueprint (I just followed a tutorial, but I’ll put it in the switch blueprint). I just had to copy paste the same thing and rearranging it a bit x) I just added a variable as integer and editable too, like the lights. Here’s my thing :