RenderStepped, Stepped, or Heartbeat

I was just wondering when should I use each one and with examples?

37 Likes

Never completely understood that diagram. How come frame 2 have different things under render than frame 1?

1 Like

Like I said, wait has a minimum wait time of a thirtieth of a second. It only resumes every other frame. I’d assume the same is true for network replication.

9 Likes

So if I’m getting this right, when does rendering happen? Before or after Stepped/Heartbeat?

Or does it happen in parallel. If it does happen in parallel, how do I make sure that things under stepped / heartbeat render at that time for after the renderstepped on the next frame?

Well posatta explained that Heartbeat runs at the end of each frame, Stepped runs before any physics happen (It happens before a part falling), RenderStepped is before any render (I assume renders are frames as well but I dont know)

2 Likes

Hello anyone coming in from Google and the great beyond! Looks like this thread pops up frequently when people are searching for which of these events to use. At the time of this question’s writing, the Task Scheduler article wasn’t yet published, but now… it is! Nonetheless, @posatta’s original response is pretty solid.

You can make an informed choice by checking out the Task Scheduler article! Some general rules of thumb, mostly echoing the contents of the article and the solution:

  • Gameplay-related stuff should use RunService.Stepped. Examples:
    • ticking damage-per-second effects
    • setting physics properties each frame (remember, Stepped happens before physics update)
  • Rendering-related stuff should use RunService.RenderStepped. Examples:
    • Re-positioning the camera
    • Updating your own tweens (not ones started using TweenService)
    • Re-positioning a ring in-world to indicate an area of effect under the mouse

An important distinction: Heartbeat fires even when the game is paused, whereas Stepped will not fire. This doesn’t mean you should always use Heartbeat, though! Make an informed decision based on what your game is doing each frame.

52 Likes

So, for example, if I want a wind factor on a golf ball, stepped would be the right choice?

You never got an answer on this thread, though I figure someone out there’s probably looking for an answer to this. Anyway…

For what it’s worth, a BodyForce is what you’d want to use for this case. Wind exerts translational force on the ball, and would probably be defined using world space…which is how BodyForce works. If the force needed to change based off location (for example), you would use Stepped to update its Force property.

Alternatively, you could modify the golf ball’s velocity property directly, but that can have some unwanted side effects.

15 Likes