Universal lights and switches?

Hi!
I’d like to implement the lights and light switches system into my project and I’m not sure how to achieve it/achieve it correctly.

The desired result - I’d like to have various types of actors representing different types of lights (chandeliers etc.) and an universal light switch actor which could be “befriended” with any of the previous mentioned lights.
In result it could be like this: there are rooms A and B. Room A has 2 chandeliers and 1 switch, B has 1 chandelier and 2 switches and any switch controls only the chandelier/s in its room.

When I was trying the very basics, I managed to toggle a point light using a trigger and a level blueprint. Maybe I haven’t simply understood the philosophy behind the level blueprints but it feels like they can become really messy soon, so I don’t feel like using it if not necessary.

My idea:
There’s a parent blueprint “universal light” which has an int variable “index”. Every light blueprints have the “universal light” as a parent, so they (I suppose) also have the “index” variable.
The switch actor also gets the variable “index” and if any of the lights have the same “index” as the switch, the switch controls them.
I guess the switch would call the “universal light” parent in a proximity and if the light being called because of it parent had the same index, it would run the toggle function.

I’m not exactly sure how it works in the UE yet, that’s how I would execute it in Game Maker with which I’ve been working for over a decade, so maybe my idea is bad in the UE’s environment, I don’t know yet.

Thank you in advance for any suggestions.

I think you’re getting a lot of concepts muddled there.

Blueprint parenting is for similar items. So you could make a blueprint parent of type Light and the children would be Chandelier and Desklamp etc.

In any event, I wouldn’t worry about any of that. The best thing is just to get a switch to talk to a light. The main way to do that would be just direct blueprint communication.

There’s bags of switch and light tutorials on utube:

Thank you for the reply

edit: sorry, I originally read “level blueprints”, not “blueprint parenting”, so I was replying to something slightly different.

So, according to the video (and other videos), the light switch is usually made using the level blueprints.
I have a question about it, how do you avoid turning it into one huge messy blueprint? The blueprints are cool but it feels like it’s really easy to turn them into a messy maze of curves, compared to the regular scripting.

Let’s say I’ll have a huge level which contains 500 actors interacting in similar ways (300 lights, 10 elevators, 20 explosives with detonators, 100 triggers with another events, … whatever), currently I imagine putting every of this relationships into the level blueprint, which sounds like a huge mess for me, especially if I wanted to find one particular relationship among all of these.
What can I do to keep it human-friendly?
I guess it could get simplified by putting the separated relationships into comments for example but it still keeps me bugging if there’s a better way.

In CryEngine 1, with which I’ve also been working for over a decade, there you can simply connect entities in the level editor. When the entity, which activates, is selected, you can pick the entity which will be activated and there appears a visible line between them. When you delete one of these two entities, the relationship naturally disappears.
Feels like in blueprints an empty relationship without its actors would probably stay until deleted manually. Can it be somehow avoided in another way than manual maintenance?

I’d tried it by myself but I won’t have time to open UE until later this day.

The level BP has a specific purpose, and managing lights and switches is not one of them :wink:

If you have a switch BP and a light BP, just connect the switch to the light by having a reference to the light in the switch, that’s it. Everything works, no need to touch the level BP.

Then you can put 1000’s of lights and switches in the level, no code whatsoever.

If you’re not clear, tell me and I’ll show you a code example.

Thank you! I think that’s the main lead I needed, I’ll take a look at it. If I won’t know how to advance, I’ll ask but I believe it’s gonna be ok.

I made the light parent and its child/ren but I don’t know how to make the reference in the switch.
If I get it right (it’s also the result I long for), in an instance of the switch, I would pick instances of the lights I’d like to switch?

I’m not sure where to link it, I guess it’s not in the blueprint, right?

In the Light Switch class, make a variable of the parent light type. Then make it an arrray or a list and check the “instance editable” checkbox. Now when you select a light switch in the level, you’ll see that property in its details panel and you can add lights to it.

Make the reference variable in your switch:

Put the switch and the light in your level, then click on the switch and tell it which light you want it to work for:

assign.JPG

Thank you both!
You’ve helped me to uncover very importantly looking parts of the UE. Not only the references but also the arrays and casting (I’ve already knew about them but never before there was an actual need to use them)

I really thank you very much!

edit: now I see there’s an error when not all of the lights are referenced. I managed to fix it when I was not using arrays, I’ll manage to fix it again.
edit 2: got it! Just removed the Cast failed

Hoorah! :slight_smile:

To make the number of lights variable you should make an array of lights instead of three separated light references.

How? I’m still quite new to the UE, so there are lots of things I don’t exactly know how they work. If there’s a better way than making separated references and then merging them into an array (which is the best solution I’ve found so far), it would be super.

You do not need them in an array :slight_smile: As I’m sure you can see, what you have is working fine, right?

Each light switch just needs to know which light it works, that’s all.

I mean this:

You can now add as many lights as you want to the array (in the world editor), not just three. You will not need to modify the blueprint if you have more than 3 lights.
And you don’t need to cast to BP_LightParent because it is already a BP_LightParent or a derived class of it which inherits “ToggleLight”, thus it has the function “ToggleLight” in every case. If BP_LightParent has the function “ToggleLight”, also BP_LightParent_Child, BP_LightParent_Child_Child and so on has this function.