Which UI tweening method is more efficient?

I’m having a dilemma about which of the two methods of tweening below is more efficient, or if there is no real variation.

I want to tween the rotation of my button when the mouse enters it, and tween it to normal when it leaves. For this, I could create the tweens each time the event is fired:

button.MouseEnter:Connect(function()
    TweenService:Create(button, TweenInfo.new(.2), { Rotation = 15 }):Play()
end)

button.MouseLeave:Connect(function()
    TweenService:Create(button, TweenInfo.new(.2), { Rotation = 0 }):Play()
end)

Or… I could define the tweens at the start and then simply play them:

local enterTween = TweenService:Create(button, TweenInfo.new(.2), { Rotation = 15 })
local leaveTween = TweenService:Create(button, TweenInfo.new(.2), { Rotation = 0 })

button.MouseEnter:Connect(function()
    enterTween:Play()
end)

button.MouseLeave:Connect(function()
    leaveTween:Play()
end)

Does anyone have any insight into whether one of these methods is more efficient than the other, or if it’d make no impact regardless of which I choose?

Thanks in advance :slight_smile:

2 Likes

The second one is technically more efficient. Being that you are creating the Tweens once, then reusing them in memory. Though it won’t really make a difference.

3 Likes

Why are you worrying about how efficient your tweens are going to be, that’s going to be the least of your problems depending on how big you plan to make your game, and well how much tweens youll have I guess

1 Like

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