Multiple Switches Flip/Flop Lights on/off ? Logic Puzzle

Hey everyone!

I am struggleing with an idea i had. It seems simple but i can’t setup the BP correctly (or I am just missing something)

This is a simple visualization of what i want to make in my BP

I have 4 clickable switches ( I already made them work with OnClicked etc. )
Each switch can turn 1 or 2 lights on/off

For example:
S1 turns L2 = ON/OFF
S2 turns L2 & L1 = ON/OFF
etc.

But what I am struggling with is that if I turn S2 on while S1 is still on, L2 should turn off, because S1 already turned it on.
So each switch can trigger multiple light to turn On/Off. I hope you can follow me and get what I am trying to say ^^

Here is my Blueprint attempt:

I already tried using Flip Flops to trigger the ON/Off but it never worked the way i wanted. I don’t know if I am on this for too long now, and can’t see the obvious, or if its just harder than i thought.

The Switch Reference is just to get the Bools of each Switch when its pressed.

btw. I didn’t use real Lights, these are just Static Meshes that change material when triggered, for testing purposes.

The function is simply that:

The Goal of the Puzzle is to turn all lights on by using the switches. When all lights are turned on, the puzzle is solved.

Hope someone can help!

Hi snairFX,

If I understand what you are trying to do correctly, then I think you want to use flow controls. I did a quick example.

You can use other controls like AND and NOT and NOR for any future stuff, here is a list of them here - Flow Control | Unreal Engine Documentation

If this has solved your problem then ive got a few more recommendations. Instead of using a Tick to keep checking variables, just call an event whenever the user does something to change it. Doing it in this event driven way reduces the amount of calls to the world tick timer which will improve your games overall performance, in my experience anyway.

And the last thing you could do is if those objects you are setting the material on are all of the same type, you could use a function and just add an input value which is of that object type. More on functions here - Functions | Unreal Engine Documentation

Here is what I came up with.

110520-flowcontrol3.png

I just feel that would only make one function which is very reusable, which just makes your blueprint easier to manage.

I hope that helps you, if you need any further assistance im happy to help. And thanks for providing good images, it really helps to understand what is going on!

Thanks,

Razer313

Edit: After a quick re-read I haven’t 100% answered your question, but you should look at using the same flow controls as I mentioned. It will just require using different nodes to all the OR’s I used. Hopefully this answer still helps you!

Thank you so much for your quick and well explained Answer !! I just edited my whole BP and it seems to work now! Thx ! I am only using 1 function to update the lights like you did, as well as the OR/AND nodes to check the switches.

And thank you for the tipps on the EventTick, i wasn’t quite sure what Event to use there. I will work on that too.

My blueprint is a total mess now. As soon as I have cleaned up the code and everything is still working, I will post my solution with screenshots!

Thanks again for the help!

So after working on it for a while I was pretty happy with my result. A combination of AND/OR nodes worked great. It’s not 100% what i had on paper, but I realised that this “Logic Puzzle” I wanted to use as a mini game inside another game, has to be dynamic, so each time the player has to solve it, the switches have to be assigned to different lights. Without setting the switches randomly each time the game starts, it would be totally boring.

This is how I made it work with your help. But I am working on setting the switches randomly right now. So I am changing things as we speak.

The S#Values are 3 random integers, one for every light. Once a switch is pressed, it will call a function which is a SwitchOnInteger that includes all my lights. So everytime you start the game, the switches will control different lights. And it works just fine aswell!

Thank you again for your help! My blueprint looks way better now and I’m progressing faster :slight_smile:

Thats fantastic, glad I could give you a push in the right direction but well done to you for being able to implement a working solution so quickly all by yourself! And thanks for providing your solution so that if other people stumble upon this post in the future it will help them out!