Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Question about storing many tweens?

Asked by 4 years ago
Edited 4 years ago

If I have many tweens, should I create all tweens in the beginning so they can be accessed with a :Play() at all times or should I only create the tween when it is needed? Which one takes less memory/which one is the best for performance?

0
Neither take less memory. "Less memory" is quite literally a joke topic, since the compiler adjusts the memory for you. DeceptiveCaster 3761 — 4y
1
Don't go out of your way to optimize a part of your game unless you notice that part of the game is causing performance issues and you know you want to keep that part of the game. Otherwise, this wastes time on optimizing code that might not even be released in the final game. hiimgoodpack 2009 — 4y
0
I think it won't do much to the memory. But it better to create all the tweens in the beginning, so you can use it when in need. Block_manvn 395 — 4y
0
Saying less memory is a joke is just inaccurate, as I have run into issues with arrays being too large and slowing server performance. zemljorog 80 — 4y
0
create them when you need them.. it's easier on memory and therefore, performance of your game. User#23252 26 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Creating numerous tweens will require them all to be stored in memory, but unless you have tens of thousands of tweens (if not hundreds of thousands), this shouldn't be a concern.

Performance wise, creating tweens in advance might save a tiny fraction of time (at the cost of "loading" them at some point), but this benefit might very well be eaten up by having to maintain them.

If you actually do have tens of thousands of tweens (all to be played within a short time of each other), you could try doing a stress test - have a script constantly generate tweens using one of the two methods and then increase the number of tweens being generated per frame until Roblox slows down. Then do the same thing for the other method. Then you can compare how slow Roblox is running with the two different methods (ex using frames per second), telling you which one is faster (if there's even a difference). You could also look at the performance window to get an idea of which one takes up more memory as well.

I recommend just creating them when you want to use them.

Ad
Log in to vote
1
Answered by 4 years ago

It's mostly personal preference. I usually create them when I need them so I don't have them just sitting in memory, but its also faster to reference an already created one to create a new one. Pay attention to your memory usage through /console. If you're using too much with storing Tweens, try creating them when you need them. This shouldn't be a problem though, unless "many" means in the tens of thousands.

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You could try this

local Tween = game:getService("TweenService")
local Tweens = {}
Tweens.Tween1 = Tween.Create(your tween here)
--all other tweens...
--When you need to run the tweens..
for _,v in pairs(Tweens) do
    v:play() -- maybe..
end

Sorry if this doesn't help You could also try running the tween As soon as it made. Again sorry if this doesn't help

Answer this question