BindToRenderStep() for multiple similar functions running at the same time

I’m wanting to connect a function to renderstepped which would run after the camera has been rendered Enum.RenderPriority.Camera.Value+1. However, :BindToRenderStep() requires a string as its first parameter - the same string which you would need to use to :UnbindFromRenderStep().

However, I’m needing to be able to :Disconnect() from this event for each individual thread running the same function, despite me having to use the same string to label the event using :BindToRenderStep() I’d ultimately end up accidentally unbinding the wrong function from RenderStepped due to them having the same string identifier. How would I go about doing this so I can run multiple threads of the same function after the camera has been rendered? Is :BindToRenderStep():Unbind() a thing, because :Disconnect() apparently is not?

Until now I’ve been using .RenderStepped and :Disconnect(), however, the renderpriority is naturally inconsistent when going about doing this that way.


If Roblox does not currently support any method for this, then I’ll need to make a feature request.

Perhaps these functions could help. Store the return value of modifiedBindToRenderStep in a variable so that you can give it to modifiedUnBindFromRenderStep (similarly to how you would store a connection in a variable and then disconnect it).

local RunService = game:GetService("RunService")

local bindNames = {}
local tickFunct = tick

local function modifiedBindToRenderStep(name, priority, funct)
    local nameWithTick = name..tickFunct().."_"
    local uniqueName = nameWithTick.. 1
    local currentNum = 1
    while bindNames[uniqueName] do
        currentNum += 1
        uniqueName = nameWithTick..currentNum
    end
    bindNames[uniqueName] = true
    RunService:BindToRenderStep(uniqueName, priority, funct)
    return uniqueName
end

local function modifiedUnBindFromRenderStep(name)
    RunService:UnBindFromRenderStep(name)
    bindNames[name] = nil
end
1 Like