Events

In GDevelop, events define the logic of a game. You can use events to create cause and effect. For example, an event might detect when the player has collided with a collectible item and, as a result, increment the player's score. You can create and manage events via the Events editor.

You don't have to be familiar with programming to create events. If you are familiar with programming though, some of the concepts will feel familiar.

List of event types

This section lists the different types of events, each of which is useful for adding different types of logic to a game. If you're not familiar with the concept of events, skip to the next section.

Refer to the linked pages to learn more about each type of event.

The most commonly used types of events are Standard events.

Conditions and actions

Events are made up of conditions and actions.

Conditions are what cause something to happen. Some examples of conditions include the player colliding with another object or a variable equalling a certain value. If an event doesn't have a condition, the associated actions run in every frame of the game.

Actions are the things that happen when a condition is true. Some examples of actions include deleting an object or incrementing the value of a variable. Without actions, events don't do anything.

Events can have multiple conditions and multiple actions. For example, an event might have a condition that checks if the player is jumping and is colliding with an enemy object, and an action that deletes the enemy object and increments the player's score.

You can use events to create custom conditions, actions, and expressions. For more information, refer to Functions.

Execution order

Events run in the order they're defined. This can have a significant effect on what happens when an event is executed.

For example, the following events create a “Square” object and then immediately deletes the object:

As a result, the “Square” object is never displayed displayed on the screen.

If an event is causing an unintended side-effect, verify that events defined earlier in the frame aren't impacting events defined later in the frame.

TimeDelta

GDevelop evaluates events and re-renders objects many times per second. How often this happens depends on the computer's resources:

On a slow computer, a game may run at 25 frames per second. On a fast computer, a game may run at 60 frames per second (this is the maximum frame rate).

GDevelop attempts to keep the frame rate consistent across computers, but since the frame rate can vary, the speed of some operations can be inconsistent.

For example, consider the following action:

This action increments a variable in every frame. If the game runs at 60 frames per second, the variable will have a value of 18000 after 10 seconds. If the game runs at 25 frames per second, the variable will have a value of 7500 after 10 seconds. This inconsistency will have a significant impact on the player's experience.

To fix this problem, GDevelop provides the TimeDelta() expression. This expression returns the number of seconds that have elapsed since the previous frame. You can use this expression to ensure that the game runs predictably at different frame rates.

For example, consider the following action:

This action also increments a variable in every frame, but the value of the variable is multiplied by TimeDelta(). This ensures that the variable increments at the same speed, regardless of the frame rate. This guarantees that all players have the same experience.

As a rule of thumb, use TimeDelta() when increasing or decreasing a value over a period of time. If your action only runs once, TimeDelta() is not required.

Creating an event

  1. Open the Events editor.
  2. Select the Choose and add an event icon.
  3. Select the type of event.

If you select the Add an event icon, GDevelop immediately creates a Standard event.

Adding conditions to an event

  1. Open the Events editor.
  2. Find an existing event or create a new one.
  3. Select Add condition.

Adding actions to an event

  1. Open the Events editor.
  2. Find an existing event or create a new one.
  3. Select Add action.

Creating a sub-event

Some types of events can have sub-events. Sub-events are events that exist within other events. These types of events only run when:

  • The conditions of the parent event are true.
  • The actions of the parent event have finished running.

To add a sub-event to an event:

  1. Open the Events editor.
  2. Select an existing event or create a new event.
  3. Select the Add a sub-event to the selected event icon.

Sub-events appear nested within their parent events.

Link, Comment, and JavaScript events can't have sub-events.