Hey, a few thing think could help you.
-
It’s good practice to keep al input interaction with the character. think you are using level blueprint for this, but since you are already creating a blueprint for the generator, consider using the generator as the one to handle the logic for your lights.
-
All those lights… you can make the engine work for you… For Example:
Here you can tell the engine on Begin Play event to search for all lights and add them to an array. In this example told the engine to search those with a specific tag allowing to have more than one generator or limit the lights affected. -
With this array of lights, you can now loop through them and do what you need:
-
For the interaction of the light, I’m running an event calling an interface. This is the event:
- First I toggle a bool (bIsOn) to know when the generator is on or off.
- Then I select the material to glow green if on, black if off.
- I toggle the tick event (more on that later)
- and for last I tell the lights to update with the event in # 3.
- For the tick event, this will only run when the generator is on.
- First: I used a float variable that holds current fuel. Used a variable that I can tweek to deplete X amount of fuel per second. For this you need to do the math expression in the image. The math should be self explanatory.
- the print node is just for debug
- And last, the branch checks if fuel is less than 0. If true, toggle the generator to turn it off.
- And last, the interface, how the player character interacts with the generator:
- The branch checks if there is fuel. If there is, then toggle on or off.
This is everything in the generator blueprint:
This is how it works: notice I can turn on / off and it shuts down when fuel <= 0.