KoTheHuman

Before I begin, Our project is running a very old version of the Spine Unity Runtime: Version 2.3.

We're experiencing some memory crashes on the Nintendo Switch, and profiling is revealing a steady increase in our Mesh memory. I'm not the most familiar with SkeletonRenderer.cs but is there dynamic mesh stuff happening there? Is there a way to manually delete mesh data or free it when its no longer being used?

Generally, I'm looking for a little enlightenment on the Spine Unity stuff, and mesh memory in general. It might help fix our Switch blocker for lotcheck.

Thanks in advance

Ko Costarella
Software Engineer, HumaNature Studios Inc
KoTheHuman
Posts: 2

Pharan

Yes, Spine skeletons are rendered as dynamic meshes by SkeletonRenderer.

Just to point how they are currently being destroyed:

You'll find the OnDestroy of SkeletonRenderer calls rendererBuffers.Dispose();
spine-runtimes/SkeletonRenderer.cs at 3.6

Which disposes the smart mesh class:
spine-runtimes/SpineMesh.cs at 3.6

Which ultimately calls UnityEngine.Object.Destroy(mesh) on the meshes.
spine-runtimes/SpineMesh.cs at 3.6

I'm not sure if Unity's Switch support may have some different behavior regarding this.
If you can iterate quickly, it may be worth checking the hideflags of the dynamic mesh generated:
spine-runtimes/SpineMesh.cs at 3.6

Also, currently, SkeletonRenderer's MeshRendererBuffers rendererBuffers is a private member so you'll have to modify SkeletonRenderer to do some things to it, either within it or from another class.

We've also had some user report mesh leaks a few months ago which we fixed. I hope you have a more recent version of Spine-Unity where those have been fixed.
User avatar
Pharan

Pharan
Posts: 5026

KoTheHuman

Hey Pharan,

Thank you for the reply!

I was able to fix the problem by changing the hide flags in SpineMesh.cs, we are using Resources.UnloadUnusedAssets during our loading sequences (we don't change scenes) and changing those flags allowed some of the meshes without reference to get cleaned up.

I realize this is a "temporary" fix as it relies on players to hit loading sequences at a certain rate, but from playtesting it seems like this is sufficient. If the issue resurfaces, I'll take a look at how meshes are destroyed

Thank you again for the tips and insight! We really love Spine and it's been so incredibly happy with how our animations have turned out in game.

- Ko
KoTheHuman
Posts: 2

Pharan

So did you have an older version of the runtime after all? Did you confirm that meshes are leaked even after the GameObjects with the SkeletonAnimation/SkeletonRenderers are destroyed?
User avatar
Pharan

Pharan
Posts: 5026


Return to Unity