Given a name of a function sent to
RunService/BindToRenderStep|BindToRenderStep, this method will unbind the function from being called during RenderStepped. This is used to unbind bound functions once they are no longer needed, or when they no longer need to fire every step.
If there is no bound function by the given name, this method raises an error. You can prevent such an error from being raised by using
pcall. For example, if you bind a function named
RunService/BindToRenderStep|BindToRenderStep, the following code would unbind the function, suppressing errors if there wasn’t already a function with the name
local RunService = game:GetService("RunService") local success, message = pcall(function() RunService:UnbindFromRenderStep("drawImage") end) if success then print("Success: Function unbound!") else print("An error occurred: "..message) end
The name of the function being unbound
Bind and Unbind a Function
This example uses the
RunService to bind and unbind a function named
printHello. First, we bind the function to the RenderStep so that fires every step. Then, after we wait 5 seconds (
wait(5)), we unbind the function.
Please note that we take caution to surround the function unbind in a pcall to prevent the code from breaking due to an error being thrown if the function name passed does not match the name of an already bound function. While we know that the function used in this example is bound when we try to unbind it, doing this is good coding practice.