Using this flashlight code that has a battery component that allows the player to refill the battery when a battery object has been interacted with:
How could I add a flickering light feature. I have a flickering Light Function Material, I just don’t know how to implement it into the blueprint.
Hey there @Jambo857! Welcome to the community! Handling the functionality for the actual flickering of the light itself depends how authored you want the flickering. I would personally lean on a timeline with a float track that activates once the battery gets to a lower value, that controls the light’s intensity variable.
Timeline documentation:
Example of a timeline affecting lights:
For the material portion, you could have a scalar parameter for the emissive portion and pass that through your material function using a dynamic material instance:
Dynamic Material Instance documentation:
Ahh if you’re just trying to set the light function at runtime, then I’d recommend making a new custom event to evaluate the charge and set the light function depending on it. Then I would run this evaluation only when you gain or lose charge:
sorry, i’ll re-elaborate. Using the flashlight code that features a battery component in the first person blueprint, how can I alter the code to apply my flickering Light Function Material to the Spot Light that is used as the ‘flashlight’. I want it to be applied when the battery is below a certain threshold - like 20 for example.
Yes, specifically the EvaluateLightLevel
custom event I showed would do that if you fired it whenever the battery level changed, so place it at the end of your DrainBattery
event before it loops and at the beginning of the battery pickup. You’d also probably want to set the light material function in the EvaluateLightLevel
to another when it evaluates false
but I didn’t add it as this was more of an example of how to do it for you to expand on.
That said, there are some structural issues with the battery drain itself firing on a 25 second delay, since the delay will tick down regardless of state so if you for example turn the flashlight off then on right at the end of the 25 seconds you can lose more charge than you would have otherwise or if done correctly you can avoid using any at all, and can be activated repeatedly by flicking the flashlight on and off. I can write up a full example that will cover the edge cases when back in office.