How can I change the material of a component by checking its tag?

Hi,
So I have these hallways with these “light bulbs” attached to each section of the wall all as components of the hallway pieces themselves. The bulb part of the light is just an emissive white material to give it a glowing effect and I want to spawn in an enemy to chase you down these hallways. The problem I was having was that the enemy was not necessarily a threat until you learn that you can die from him. So I wanted to either flicker the lights or dim them, but to do that I wanted to turn off the lights. I was able to use an array and access all of the actual lights (point lights, rect lights, etc) and change their light intensity. I’m having trouble doing the same thing for the bulb materials and changing them. To affect the lights, I have empty actor blueprints that, when spawned in, affect the world as intended. I attached some screenshots of my blueprint showing the one that doesn’t work with accessing the component’s material and the other one that shows how I was able to access the intensity of the point light and change it. I appreciate the help as I am very new to UE4 and using their blueprint scripting!

Hey, thanks for the quick response! So I’m pretty sure that would work and if it comes down to it, I can do it that way. But the problem that I’m running into is that I’m trying to find the actors with their tags because the hallway pieces aren’t of the same class. Some are corner pieces while others are straight and so on. I probably should’ve made them a child of a parent “hallway” class but I didn’t think of it at the time. So I was wondering if there was a way I can access all of the pieces by their tags or if there is another way I can access all of them without making a bunch of different arrays and looping through them (which isn’t the end of the world and your code above works), I just want to know if there may be a more efficient way of doing it. Thank you again for your help!

How about this?

The ‘correct’ way of doing it would be using an event dispatcher. On begin play, your hallway segments should bind to a central actor which can trigger and event which causes the lights to change color / flicker.

If you want to subdivide them, you can still use tags, and the ‘control’ actor could pass the tag in the dispatch.

Event dispatchers are a way of talking to a lot of blueprint simultaneously:

Ok, I see how that can work. I’m just confused about how I would create the event dispatcher. I added one to my character to be called when I press a certain key just to test it for now. But where do I actually make the graph for the event dispatcher when it’s called?

The dispatch comes from your character, in this case ( absolutely fine, BTW ). The handler is written into the code of the corridor segment ( or the thing that contains the light ).

So you only have code in 2 places. The caller ( dispatcher, your character ), and the corridor BP. And because all the pieces of corridor are instances of the corridor BP, they all have the handler code by default, and can react.

Does it make sense?

Oh ok, I understand now. I got it to communicate to each hallway piece. The last thing I think I’m having trouble with is if there is a way to put all of the light components into an array (II have them tagged) and loop through them and do whatever I need to the lights. But I can’t find a node that will work with that.

No, you’re missing it :slight_smile:

Once you have the handler in the corridor pieces, you can send the lights any message you want with one event. That’s it, they all respond.

I’ll know something together, hold on…

Ok, so I made a section of corridor with a light in

The code inside binds to the controller blueprint

I dispatch the event from the corridor controller when I press a key

I put 3 bits of corridor, and the control blueprint in the level ( arrow shows the controller )

Now I can turn the lights on and off with one button press:

346558-lights.gif

Oh wow, that simplified it a lot. I got everything working and now I understand event dispatchers. Thank you so much for your help I really appreciate it!!

You’re welcome.