RunService BindToRenderStep Clarification

Hello,
I’m relatively new to coding; I’m currently getting more experience with camera manipulation.

Firstly, if I understand RenderStep correctly it’s used to call a function at a certain period of studio’s startup/current state (e.g. in this case when the default roblox camera scripts are loaded)?
Secondly, I’ve noticed the code below runs in a continuous loop. If I were to remove the Bind and manually create a while loop why does it not work?

function cameraChange()
	local camera = workspace:WaitForChild("Camera")
	camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end
runService:BindToRenderStep("IsometricCamera",Enum.RenderPriority.Camera.Value,cameraChange)

While loop instead of using RenderStep that doesn’t work

function cameraChange()
	local camera = workspace:WaitForChild("Camera")
	camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end

while task.wait() do
  cameraChange()
end
1 Like

From what you shared, there’s nothing in your script that unbinds it,

RunService:UnbindFromRenderStep("IsometricCamera") -- Unbinding the function
1 Like

Well yeah I know that I don’t want to unbind it. It’s for a title screen so it needs to remain at that position

By this, do you mean doing:

function cameraChange()
	local camera = workspace:WaitForChild("Camera")
	camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end

while task.wait() do
  cameraChange()
end

?

I do indeed. I realized just a second ago it could be misunderstood and that was probably what your initial post was about.

1 Like

Yeah sorry, misunderstood the first time lol. You should mark the post as a solution :wink:

1 Like

Haha, I edited it to clarify. Apologies for the obscurity in the post

BindToRenderStepped Is used to Bind a function at a Priority, It allows you to run things before others, and things after others, Its basically RenderStepped, but under a set order, as RenderStepped will fire in any order.

The Reason it runs in a loop, is because RenderStepped runs prior to something Rendering every frame, which if you have 40 FPS, every 1/40 of a second, this event will fire 40 times a second.

Its best that you use workspace.CurrentCamera, whixh is much faster than waiting for the Camera Instance.

Doing this would be the exact same as doing RunService.Heartbeat which is slower, as it is Prioritized last.

Roblox Recommends you Handle Camera Stuff with RenderStepped however.

1 Like

So in this case, this loop doesn’t work because as you said it’s prioritized last? And even if this is the case shouldn’t it still override the default camera either way since it’s changing the CFrame constantly?

1 Like

The while loop is changing the CFrame yes, but the Core scripts are changing the camera CFrame too if you dont turn the camera type to:
camera.CameraType = Enum.CameraType.Scriptable

Otherwise core scripts still manipulating the camera. But, do not use a while loop to manipulate the camera, use the RenderStep as suggested

2 Likes