Toggling night vision during gameplay
Turn the effect on and off from Blueprint, with a smooth transition.
The effect can be turned on and off at runtime by changing the Intensity parameter.
Step 1: Create a Dynamic Material Instance
In your character Blueprint, on Event BeginPlay:
- Add a Create Dynamic Material Instance node and set its Parent to a preset.
- Save the result in a variable, for example
NV_Material. - Get your Camera Component and call Add or Update Blendable, with
NV_Materialas the Object and Weight set to 1. - Call Set Scalar Parameter Value on
NV_Materialwith Parameter NameIntensityand Value0, so the effect starts off.
Step 2: Toggle it
On your input event:
- Call Set Scalar Parameter Value on
NV_Material. - Set Parameter Name to
Intensity. - Use
1to turn it on and0to turn it off.
Smooth transition
For a smooth power-on effect, drive Intensity with a Timeline that goes from 0 to 1 over about 0.5 seconds. Play it forward to turn on and reverse to turn off.
Switching presets at runtime
Static Switches cannot change at runtime. To switch to a preset with different modules, create a new Dynamic Material Instance from that preset and call Add or Update Blendable again. Scalar and color parameters, however, can be changed at any time.