【Godot】White Flash Damage Effect Using the Modulate Property

Created: 2025-06-20Last updated: 2025-12-16

Learn how to implement a white flash effect when characters take damage in Godot Engine using the modulate property and Tween. Includes performance considerations and advanced examples.

Overview

In action games, the "impact" when players land hits on enemies or receive damage is a crucial element that greatly affects the game's satisfaction. One of the simplest yet most effective techniques for conveying this impact is the white flash, where characters briefly glow white.

In Godot, you can easily implement this white flash effect with just a few lines of code and Tween, without needing difficult shader knowledge. The key is the modulate property.

Godot Knockback Effect

How the modulate Property Works

modulate is a standard property on all 2D nodes that inherit from CanvasItem (Sprite2D, Label, ColorRect, etc.). By setting a Color to this property, you can multiply the color tint of that node (and all its children).

  • modulate = Color(1, 1, 1) (white): Same as the original color (default state)
  • modulate = Color(1, 0, 0) (red): Only the R component of the texture remains, giving a reddish tint
  • modulate = Color(0.5, 0.5, 0.5) (gray): Overall darker
  • modulate = Color(1, 1, 1, 0.5) (semi-transparent): Alpha value controls transparency

Why Does It Glow White? HDR (High Dynamic Range) Effect

The most interesting feature of the modulate property is that color values can be set above 1. Normally, colors are expressed in a range from 0 (no light) to 1 (original color), but when you set modulate's RGB values above 1, the sprite is treated as HDR (High Dynamic Range) color and begins to glow as if illuminated from within. This creates a "blown out" expression, which is the principle behind white flash.

For example, setting modulate = Color(10, 10, 10) will make the sprite glow almost pure white regardless of the original texture color.

Basic Implementation: Smooth Transitions with Tween

A white flash is an animation sequence of "instantly turning white, then smoothly returning to the original color." To implement such time-based processing, Godot provides a very powerful and convenient feature called Tween.

Here's a reusable function that applies white flash to a character that takes damage (a node with a Sprite2D named sprite):

# Script on CharacterBody2D, etc.

# Manage Tween as instance variable (for controlling consecutive damage)
var flash_tween: Tween

# Function called externally when damage is received
func apply_damage_effect():
    # ... Processing like reducing HP, starting invincibility time ...

    # Start white flash processing
    _start_white_flash()

# Internal function to execute white flash
func _start_white_flash():
    # Cancel any already running Tween
    if flash_tween and flash_tween.is_valid():
        flash_tween.kill()

    # 1. Instantly turn sprite white
    $Sprite2D.modulate = Color(10, 10, 10) # Large values make it glow white

    # 2. Create Tween and build animation to smoothly return to original color
    flash_tween = create_tween().set_trans(Tween.TRANS_QUINT).set_ease(Tween.EASE_OUT)

    # Change $Sprite2D's modulate property to Color(1, 1, 1) over 0.3 seconds
    flash_tween.tween_property($Sprite2D, "modulate", Color(1, 1, 1), 0.3)

Code Explanation

  1. The flash_tween instance variable manages the Tween. This allows canceling the previous Tween and starting a new flash when taking consecutive damage.
  2. When _start_white_flash is called, $Sprite2D.modulate is first set to a Color with very large values. This instantly makes the sprite glow white.
  3. create_tween() creates a new Tween object. Here, method chaining with set_trans and set_ease configures the animation's easing. The combination of TRANS_QUINT and EASE_OUT creates sharp movement that starts quickly and ends slowly.
  4. tween_property() is the core of the animation. This method specifies "which object's" "which property" to change "to what value" "over how much time."
  5. The Tween automatically plays when created and is automatically destroyed when complete, so implementation is done.

Note: If large values like Color(10, 10, 10) don't work, HDR may be disabled in project settings. In that case, try values around Color(2, 2, 2) to Color(3, 3, 3).


Common Mistakes and Best Practices

While effects using modulate are easy, there are several points for writing more polished code. Let's compare common beginner mistakes with recommended designs.

Common MistakeBest Practice
Using counter variables in _process to manually animateUse Tween or AnimationPlayer to describe animations declaratively
Setting modulate directly to Color(0,0,0), making it black/invisibleTo glow white, RGB values must be greater than 1. Even when darkening, leaving some brightness like Color(0.1, 0.1, 0.1) instead of Color(0,0,0) gives better texture
Mixing damage processing and effect processing in the same functionUse Signal to separate damage detection logic from visual effects. This prevents effect changes from impacting logic
Calling create_tween() repeatedly without cleanupWhen effects occur in rapid succession, kill() existing Tween before creating new ones to prevent unintended behavior

Comparison with Alternative Patterns

modulate isn't the only way to implement white flash. Let's compare with the typical alternative: shaders.

Featuremodulate + TweenCustom Shader
Ease of Use◎ Very easy. Implementable in a few lines of GDScript△ Requires learning shader language (Godot Shader Language)
Performance○ Very lightweight. Rarely problematic even with many objects○~△ Depends on shader complexity. Simple ones are light, complex ones can be heavy
Expressiveness△ Limited to color multiplication and alpha value changes◎ Infinite. Pixel-level control over any visual effect: outlines, dissolve, glow, etc.
Recommended UseSimple effects like damage flash, item pickup glowElaborate visuals like special boss entrance effects, custom particle expressions

For most damage flash expressions, the modulate and Tween combination is the optimal choice from ease of use and performance perspectives.

Summary and Next Steps

This article explained how to implement white flash effects using Godot's modulate property and Tween. This technique is a cost-effective method for providing clear feedback to players and enhancing game satisfaction.

  • modulate: A property that multiplies CanvasItem colors. Values above 1 create HDR-effect white glow.
  • Tween: A powerful tool for smoothly changing properties over time.

Having mastered this simple yet profound technique, consider challenging yourself with these topics:

  1. Adding Sound Effects: Playing a short sound effect simultaneously with the white flash makes feedback significantly richer.
  2. Using AnimationPlayer: Suitable for managing complex sequences combining multiple animations like blinking, color changes, and shaking.
  3. Introduction to Shaders: When modulate isn't enough, step into the world of shaders. Make character outlines glow, add noise—the range of expression becomes infinite.