Ways to simplify?

As a training, I made a traffic light sequence blueprint yesterday.

It has Eastern European sequence, so it has 6 cases.

  • 0 - yellow blinking
  • 1 - red
  • 2 - red yellow
  • 3 - green
  • 4 - green blinking
  • 5 - yellow

It changes the case according to an integer timer, something like: “if 1000 > timer >= 1500 then case = 2”.
Every light has a boolean which is changed by the current case.
Also there’s a boolean “isWorking” which switches between case 0 and the other cases.

The sequence works perfectly but I guess the blueprint is a little too much big, which could result into annoying complications in a future.

Please, do you have any tips and suggestions how to simplify the blueprint? I’m not used to the UE4 programming yet and I don’t know, what everything it can offer.

Use arrays, enums, structs and variables.
For eg you can add enum that describes state of light.
Then you create struct that keeps color, boolean for blinking or not, time etc is single struct.
Then you can make array of structs. that describe every possible state of light.
And then you make function that fetches that data from array of structs when given enum with state.

Or you can do all above and use Finite State Machine plugin for unreal. It is even more fun that way.

for blinking etc you can use timeline or anim that animates color.
you can also make material with linearinterpolate beetwen 2 colors
then feed that material with color for blinking.

You got me thinking, this is nice problem. :wink:

you have 3 lights, you need to describe state of all 3 for each phase.
for each light you need 2 color variables:

  • maximum color
  • minimum color
    For eg. yellow for blinking you set maximum to yellow, minimum to black
    for yellow turned off, you set both to black
    for yellow not blinking both set to yellow.

Then enum that describes blinking, light_on, light_off. and function that when given this enum and maximum color (like red green blue), gives out maximum and minimum color.
then you just feed results of that function to each light.

This may land me in trouble as its something most big programming books would balk at typically. But f’it, when you know the form - its ok to break the rules… :stuck_out_tongue: Suggestion: Just use the material-name (of each traffic light color) as the state, and be done with it. The material name can be set to match whatever state the system is in, while simultaneously actioning that state!

So no bools or enums or branches here (or whatever switch on int / enum is in that low res image as its not clear)… You would not normally do this in most real world cases. But game work is so highly-visual, you can get away with it. When you then need to order the light changes, you just add the materials in order to an array and pick them off one by one to set the desired state.

You are right, that is the simplest way.

Thank you for your answers. :slight_smile:
I’ll take a look at it tomorrow and I’ll try to optimalise it using what you’ve mentioned.

PS: the switch uses enum.