Hello! I'm trying to pool the SkeletonGraphic component instead of instantiate (and then destroy) a prefab every time that some screen open. The only parameter that I need to change is the SkeletonData Asset, that depends which character I choose to appear.
The problem here is just because I need to re-initialize the SkeletonGraphic all over again when the SkeletonData Asset change.
That said, what is the best way to pool SkeletonData Assets?
And if that isn't a best practice, what could I do in this case?
Stranica: 1/1.
matheus_
4 months ago
- matheus_
- Postovi: 2
Luke
Hello, please see this post from Pharan and see if it assists you with better understanding the advantages and disadvantages of using pooling.
Best way to pool Spine gameObjects
Best way to pool Spine gameObjects
4 months ago
- Luke
- Postovi: 119
Harald
Please note that the part in Pharan's post "If you swap out a SkeletonAnimation's SkeletonData asset, it needs to reinitialize and orphan old objects and allocate memory for new ones." depends on the situation, and might be incorrectly worded.
In general:
1)
2) When creating an instance, instance data
So by creating a pool for each skeleton type (for each
If you have a single
Regarding how to best pool SkeletonDataAssets:
Probably the easiest way would be to write a script that holds a List of
In general:
1)
SkeletonData
needs to be loaded once for each type of skeleton (so for a SkeletonDataAsset
). This will be loaded with the first skeleton instance.2) When creating an instance, instance data
skeletonAnimation.Skeleton
and skeletonAnimation.AnimationState
needs to be created.So by creating a pool for each skeleton type (for each
SkeletonDataAsset
), you still benefit of moving the load-time to e.g. the start of a level. This optimizes item (1) above.If you have a single
SkeletonGraphic
object and swap out SkeletonDataAsset
references and thus need to re-initialize it, you don't gain (2). This is what Pharan described as "will not help much".Regarding how to best pool SkeletonDataAssets:
Probably the easiest way would be to write a script that holds a List of
SkeletonDataAsset
s and then upon Start()
loads each SkeletonData by calling e.g. skeletonDataAsset.GetSkeletonData(true);
. [Edit: removed an unnecessary line that turned out to be redundant] 4 months ago
-
Harald - Postovi: 4101
matheus_
Hi guys, thanks a lot for the replies! It is always good to understand all these nuances, so I'll test the solution that Harald proposes and see if it fits in what I need.
4 months ago
- matheus_
- Postovi: 2
Harald
After writing this line noticed that saving the returnedmatheus_ je napisao/la:var dataToStore = skeletonDataAsset.GetSkeletonData(true);
and then stores this object in a list (so that it does not get deleted again upon GC).
SkeletonData
object is not necessary, since it's cached at the SkeletonDataAsset
anyway. So please ignore the line saying that you need to store the object to avoid GC. I have removed this line from the above posting so that it's not confusing others. 4 months ago
-
Harald - Postovi: 4101
Mark topic unread
• Stranica: 1/1.
Natrag na Unity
- Vremenska zona: UTC