Hi,
In our project we are reusing the skeleton animator and just change its skeleton data asset. When we were using spine runtime 3.4 this worked fine. Now with 3.6 we have some index out of bounds issues caused by the slotindex variable in the component classes in the animation.cs file. It seems it still uses its old value and causes mayhem.
This is what we do when we change the skeleton data asset
skeletonAnimator.skeletonDataAsset = mGameIconProperties.symbolData.skeletonDataAsset;
skeletonAnimator.Initialize(true);
skeletonAnimator.Skeleton.SetSlotsToSetupPose();
symbolAnimator.runtimeAnimatorController = mGameIconProperties.symbolData.runtimeAnimatorController;
symbolAnimator.Rebind();
Should we be doing something more here?
Also, there's a memory leak when doing this. We fixed it by adding this code in skeletonrenderer.cs
if (meshFilter.mesh != null)
{
DestroyImmediate(meshFilter.mesh);
}
public virtual void Initialize (bool overwrite) {
if (valid && !overwrite)
return;
// Clear
{
if (meshFilter != null)
{
meshFilter.sharedMesh = null;
if (meshFilter.mesh != null)
{
DestroyImmediate(meshFilter.mesh);
}
}
meshRenderer = GetComponent<MeshRenderer>();
...
Found the problem.
It's because the previousAnimations list doesn't get reset when MecanimTranslator gets reinitialized. This means old slotIndexes and boneIndexes for every timeline are carried over and applied to the new animation, which may not have as many bones and/or slots, and even if it does, chaos :rofl: .
So just to be safe I removed this line and force a new MecanimTranslator every time a new skeletondataasset is changed for skeletonanimator.
In skeletonanimator.cs
public override void Initialize (bool overwrite) {
if (valid && !overwrite) return;
base.Initialize(overwrite);
if (!valid) return;
//if (translator == null) translator = new MecanimTranslator();
translator = new MecanimTranslator();
translator.Initialize(GetComponent<Animator>(), this.skeletonDataAsset);
}
:bang:
My reply got pasted onto the privous post... hm