How to Neatly/Efficently nest multiple signals?

Hey there! I was wondering if there was a better way to implement the code below. As you can see It doesn’t look too neat and It seems like it would hurt performance. Would there be a better way to imbed multiple keyframe signals?

Example of what currently have:

    curAnim:GetMarkerReachedSignal("FirstSignal"):Connect(function()
        -- DO STUFF
        curAnim:GetMarkerReachedSignal("NextSignal"):Connect(function()
            OtherAnim:Play()
            -- DO MORE STUFF
        end)
        NextAnim:Play()
        curAnim:GetMarkerReachedSignal("NextNextSignal"):Connect(function()
            otherOAnim:Play()
        end)
    end)

Thank you!

bit confusing the way you’ve set this up but here we go

local Runner
Runner = function()
	(curAnim:GetMarkerReachedSignal("NextSignal")):Once(function() -- These are all one-time listeners, they'll be GC'ed when called.
	  OtherAnim:Play();
	end);
	NextAnim:Play();
	(curAnim:GetMarkerReachedSignal("NextNextSignal")):Once(function()
	  otherOAnim:Play();
      -- I assume this signals a restart to the tree.
      (curAnim:GetMarkerReachedSignal("FirstSignal")):Once(Runner)
	end);
end

(curAnim:GetMarkerReachedSignal("FirstSignal")):Once(Runner); -- Connect using once, you can just re-hook this.

Alternatively, you could listen for curAnim’s looped event and re-attach the listener then.

Hope this helps

1 Like

Thx mate, Never head of the :Once method before. Definitely Better!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.