---
name: "SDL_HapticEffect"
section: "3type"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_HapticEffect"
---

# SDL\_HapticEffect(3type)

The generic template for any haptic effect.

## NAME

SDL\_HapticEffect - The generic template for any haptic effect.

## HEADER FILE

Defined in SDL3/SDL\_haptic.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**typedef union SDL\_HapticEffect** **{**     **/\* Common for all force feedback effects \*/**     **Uint16 type;                    /\*\*\< Effect type. \*/**     **SDL\_HapticConstant constant;    /\*\*\< Constant effect. \*/**     **SDL\_HapticPeriodic periodic;    /\*\*\< Periodic effect. \*/**     **SDL\_HapticCondition condition;  /\*\*\< Condition effect. \*/**     **SDL\_HapticRamp ramp;            /\*\*\< Ramp effect. \*/**     **SDL\_HapticLeftRight leftright;  /\*\*\< Left/Right effect. \*/**     **SDL\_HapticCustom custom;        /\*\*\< Custom effect. \*/** **} SDL\_HapticEffect;**

## DESCRIPTION

All values max at 32767 (0x7FFF). Signed values also can be negative. Time values unless specified otherwise are in milliseconds.

You can also pass  **SDL\_HAPTIC\_INFINITY**\
  to length instead of a 0-32767 value. Neither delay, interval, attack\_length nor fade\_length support  **SDL\_HAPTIC\_INFINITY** . Fade will also not be used since effect never ends.

Additionally, the  **SDL\_HAPTIC\_RAMP**\
  effect does not support a duration of  **SDL\_HAPTIC\_INFINITY** .

Button triggers may not be supported on all devices, it is advised to not use them if possible. Buttons start at index 1 instead of index 0 like the joystick.

If both attack\_length and fade\_level are 0, the envelope is not used, otherwise both values are used.

Common parts:

-

  ```
   // Replay - All effects have this
   Uint32 length;        // Duration of effect (ms).
   Uint16 delay;         // Delay before starting effect.
   // Trigger - All effects have this
   Uint16 button;        // Button that triggers effect.
   Uint16 interval;      // How soon before effect can be triggered again.
   // Envelope - All effects except condition effects have this
   Uint16 attack_length; // Duration of the attack (ms).
   Uint16 attack_level;  // Level at the start of the attack.
   Uint16 fade_length;   // Duration of the fade out (ms).
   Uint16 fade_level;    // Level at the end of the fade.
  ```

Here we have an example of a constant effect evolution in time:

-

  ```
   Strength
   ^
   |
   |    effect level -->  _________________
   |                     /                  |                    /                    |                   /                      |                  /                        | attack_level --> |                         |                  |                        |  <---  fade_level
   |
   +--------------------------------------------------> Time
                      [--]                 [---]
                      attack_length        fade_length
   [------------------][-----------------------]
   delay               length
  ```

Note either the attack\_level or the fade\_level may be above the actual effect level.

## AVAILABILITY

This struct is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_HapticConstant**(3type)](/SDL_HapticConstant/3type.md), **•**(3), [**SDL\_HapticPeriodic**(3type)](/SDL_HapticPeriodic/3type.md), **•**(3), [**SDL\_HapticCondition**(3type)](/SDL_HapticCondition/3type.md), **•**(3), [**SDL\_HapticRamp**(3type)](/SDL_HapticRamp/3type.md), **•**(3), [**SDL\_HapticLeftRight**(3type)](/SDL_HapticLeftRight/3type.md), **•**(3), [**SDL\_HapticCustom**(3type)](/SDL_HapticCustom/3type.md)
