I don't think I understand sub events

Been plucking at Gdevelop off and on for a while and I don’t think I understand how sub events work at all. Feels like hit or miss to get things to work with sub events so I end up using a lot of parent/normal events, and I think that’ll probably harm performance.

For example, something like:

If mouse left pressed > play tween “turn green”

if tween “turn green” is finished > play tween “red”

Never works right. It’s like it either skips the parent/jumps to the sub event, ignoring it. Or it ignores the sub event. In the case of a tween animation, it plays the first event but not the sub. The majority of the time it just dismisses the sub events completely. That’s why I’m wondering if anyone can explain how to properly trigger sub events in a way I might understand how to use them.

In this case you shouldn’t use it a sub event.
Tweens are slightly different from other actions, but generally applies sub events are executed directly when they are true.
Until the green animation is finished, you no longer press the mouse, the parent condition is no longer true and subs can no longer be executed.
Without “Trigger once” the tween is started very often, add it or replace mouse pressed with mouse relesed, preferably both.

A subevent triggers when the above condition is still true and if its own conditions are true. That means that you’ll have to still be pressing the mouse button to trigger the subevent. If that si indeed what you want, then you probably want to do

If mouse left pressed

if trigger once > play tween “turn green”

if tween “turn green” is finished and trigger once > play tween “red”

To make sure you are not constantly restarting the tween preventing from the end condition to ever trigger.

If what you want is to have the turn green always trigger once the red tween finished independently from clicking the mouse, then you don’t want to use subevents:

If mouse left pressed and trigger once > play tween “turn green”

if tween “turn green” is finished and trigger once > play tween “red”

Note that you almost always want to use trigger once when starting any kind of animation to never endlessly restart it.

Thank you so much for the replies! I think I’ve narrowed down what I’ve been doing wrong/what my thought process was.

I’ve been using the conditions as AND in my mind, not ALL MUST BE MET/TRUE.

I’ll try to be more careful and thoughtful with my sub events from now on, thanks!

here a little subevent tree i made to explain the relation of main event/subevent.

1 Like