Do Animation Connections get Disconnected after Stop()/BeingFinished?

Basically, I want to connect to the animation to see if it reaches a certain marker, lets say the marker’s name was “Cheese” and I want to “Pause/AdjustSpeed(0)” so:

MyAnimation:GetMarkerReachedSignal("Cheese"):Connect(function()
-- My code/blablabla
end)

I was wondering, would It get disconnected after the animation stops/I Stop() it/ would It cause memory leaks?

3 Likes

Try an experiment:

  1. Connect your marker signal with a print statement.
  2. Play your animation.
  3. Stop it right after it reaches the marker.
  4. Play the animation once more and let it play until it reaches the end.

If the output window shows your printed text twice or shows (x2) next to it, then no, it does not disconnect your event. Otherwise, yes it does.

4 Likes

Thats quite annoying, what would be the best way to disconnect it? Would it be just to do a normal Disconnect() right after its finished? (The animation is gonna happen multiple times)

2 Likes

This is how to disconnect a listener: Store the connection object in a variable and then call Disconnect on it when you want to disconnect it.

local connection = animation:GetMarkerReachedSignal("Thing"):Connect(f)
wait(5)
connection:Disconnect()
2 Likes

Guess I’ll just do it the normal way as always, thanks :+1:

2 Likes

Animation connections are still RBXScriptSignals, so they fall under the same rules as any other connection. If the object still exists, then so will the connection. Destroy objects you don’t need anymore and disconnect connections you don’t need.