Difference between these in our own behavior

What is the difference between


and
.
Although, I found out about what they do but what are the advantages of using one of these. And which one should I use for my do always event of behavior.

So my understanding is the engine reads/executes all the events, top to bottom every single frame.

When you have logic in doStepPreEvents you’re basically telling the engine to read/execute that logic before anything else.

The opposite is true for doStepPostEvents, it’s after everything has been read/executed.


With out knowing what you’re trying to achieve, it a bit hard to tell you which one you should use. For example, you would not really want to use doStepPreEvents to change a sprites animation based on if it’s colliding with something as the logic to check if it was colliding would not have been run for that frame yet.

For making player’s movement

For now, I am using doStepPreEvent

That’s a hard one. I personally would not use doStepPreEvent as you could run into an issue where you’re moving the character before any events say you shouldn’t for that frame.

An example, you have a variable that checks if the player is allowed to move or not. This is disabled if the player dies.

FRAME 1

doStepPreEvent is fired, player is moved 5 pixels to the left.
Player has 1 HP.
Frame Events Finished.

FRAME 2

Everything was fine in the previous frame
doStepPreEvent is fired, player is moved 5 pixels to the left.
Player loses 5 HP, is dead. Enable enable the variable that stops the players movements.
Player collides with +5 health within the same frame, now bringing the players health to 5.

FRAME 3

Player is unable to move due to variable being disabled in last frame.
doStepPreEvent is fired, player is unable to move.
Player is still alive, unable to move.

The chances of all the above happening a pretty low, but you should be able to see why it might be a bad idea to move the player at the start based off the events of the previous frame.
If the movement wasn’t done before the check, in frame 2 the player would never have collided with the +5 health as the variable to stop movement would have been enabled.

That’s just my understanding of the system, there might be someone who has worked directly with the engine who can provided a better understanding.

1 Like

Thanks @Eiklahc. Thanks for the explaination.

1 Like