Can somebody share how to make an emissive material toggle switch on and off using key input method?

Can somebody share how to make an emissive material toggle switch on and off using key input method?

Hello @ShinJavier ,Welcome to the forums!

To achieve this, first create an Input Action, in this case called IA_ChangeColor


and add it to your Input Mapping Context. In the Triggers section, add a Pressed Trigger so the event is executed when the key is pressed.

Next, create a Material with a Vector Parameter for the color and a Scalar Parameter called Glow. Multiply both parameters and connect the result to the Emissive Color input.

Then create a Blueprint Interface, in this case BPI_ChangeColor, with a function called ToggleLight. This allows the Character to communicate with any actor that implements the interface without creating direct references.

Add the interface to both the Character Blueprint and the Blueprint you want to modify.

Inside the Blueprint that will react to the interaction, create a Dynamic Material Instance in Begin Play and promote it to a variable so it can be accessed later. Then initialize the Glow parameter to 0 so the object starts with the emissive effect turned off.
Next, implement the ToggleLight interface event and use a FlipFlop node to alternate the Glow value between 0 and 400. This will turn the emissive effect on and off each time the event is called.

Finally, in the Character Blueprint, create a Sphere Trace by Channel when the assigned key is pressed. If the hit actor implements the BPI_ChangeColor interface, call ToggleLight(Message) on the Hit Actor to enable or disable the glow effect on that Blueprint.

Hope it helps!