Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why use RenderStepped when you can use HeartBeat?

I see a bunch of developers use the .RenderStepped event to run a block of code every frame. Though if RenderStepped runs it every render frame and .HeartBeat runs it every game frame, wouldn't there be no need for RenderStepped? If my understanding of the two terms is correct, running a loop with renderstepped would run code multiple times per HeartBeat, which is inefficient, since the user only sees the visible effects every HeartBeat.

The only practical usage I could see is eithier with managing physics or working with networking between client and server.

2 comments

0

RenderStepped is client-side only

0

Yes I understand that, though my question is why would you use it (on the client) when HeartBeat does it every visible game frame.

1 answer

✓ Accepted answer

Because, as the names imply, RenderStepped is related to rendering and Heartbeat is not.

In each frame, RenderStepped fires first, the frame waits for it to yield, then the render and stuff like heartbeat run parallel. Heartbeat fires last after physics.

So RenderStepped is the best option for render stuff, and if you are only concerned with doing stuff "every frame", RenderStepped in the worst option because rendering will yield unnecessarily. Nothing waits for Heartbeat.

Heartbeat should be used for everything unrelated to rendering.

2 comments

0

Ah so apparently I was misunderstood that Heartbeat doesn't yield for code like RenderStepped and BindToRenderStep does, and it runs asynchronously, right?

0

Exactly

This discussion is preserved as it was. New answers, comments, and votes are closed.