• RuntimesUnity
  • 在播放动画时,内存中的重复材质大量增加

你好!我遇到一个内存泄漏的问题,在Skeleton Mecanim的Mask Interaction设置为Inside Mask时,运行时内存中会每帧不停创建相同的材质,导致内存泄漏,请问是我的spine资源导出有问题吗?

可以看到材质的数量在不停上升,在内存快照中有大量相同的材质

我的场景中只有一个spine物体,这个物体导入unity中有两个材质

请问是我哪里使用出错导致了这样的情况吗?期待回复

Related Discussions
...

你好!在使用Skeleton Mecanim时,如果内存中不断创建相同的材质,可能是由于代码中某些地方错误地创建了新的材质实例。确保你使用的是最新版本的spine-unity运行时,因为旧版本可能存在已修复的bug。你可以尝试以下步骤来解决问题:

  1. 确保你使用的是最新的spine-unity运行时版本。可以从Spine Unity下载页面获取最新版本。
  2. 检查代码中是否有不必要的材质实例化操作,尤其是在动画播放或更新时。
  3. 如果你在运行时进行材质或纹理的动态修改,确保在不再需要时正确释放这些资源。可以使用AtlasUtilities.ClearCache()Resources.UnloadUnusedAssets()来清理不再使用的资源。

如果问题仍然存在,建议创建一个最小的Unity项目来重现该问题,并检查是否在其他项目中也会出现相同的行为。

    Spinebot 你好!我的运行时版本是4.3.2,应该是最新的。我并未添加任何代码动态创建游戏对象,只是将预制体拖入到场景中。

      hjx1994 Please note that 4.3 is still a beta version, and skeleton data exported from the latest editor may not work correctly at runtime. If you are developing for production rather than testing, please use the latest stable version, 4.2.

        Misaki 你好!我将版本修改为4.2后进行测试,依然会有这个问题

        Misaki 编辑器版本是4.24,运行时版本为4.2

          hjx1994 I see, thank you for trying the 4.2 editor and runtime! In order to identify the cause of the issue, could you please send us the minimal Spine project that reproduces the issue via email?: contact@esotericsoftware.com
          Please include the URL of this forum thread in the email so we know the context. Then we can take a look at what's wrong.

            @hjx1994 Thanks for sending the reproduction project, we received everything. We will get back to you here on the forum once we've figured out what's going wrong.

            @hjx1994 Thanks for reporting and sorry for the troubles! This was indeed a bug where mask materials were unnecessarily re-created. This has now been fixed on the 4.2 branch.

            A new spine-unity 4.2 unitypackage is available here as usual:
            https://esotericsoftware.com/spine-unity-download
            Please let us know if this resolves the issues on your end as well.

            Issue ticket for later reference:
            EsotericSoftware/spine-runtimes2848

              Harald 感谢!我尝试新版本后问题已解决,解决问题的速度让人惊讶,再次感谢!

              Harald 你好!!!!更新后我遇到了新的问题。在使用SkeletonMecanim时,多材质的Spine在设置Mask Interaction不为None后会显示错误!
              这是我未设置Mask Interaction值的样子

              这是我设置未Visible inside Mask后,

              为了可以在编辑器中看到对象,我重新设置为None

              可以看到,我的脑袋没了 T-T。我观察只生成了一个InsideMask材质,没有为每个材质都生成InsideMask材质。

              @hjx1994 Very sorry for the troubles and thanks for reporting! Unfortunately the mask handling structures in the 4.2 spine-unity runtime is suboptimal, and fixing it one way would introduce different memory leaks, and also risking breaking existing projects. As a result I've reverted the last commit, sorry to say.

              The good news is that we have already solved this problem via a better mask architecture already in an internal dev branch, which will be released in the current beta branch alongside with threading implementation as soon as the final cleanup is done. Unfortunately it will take a bit of time still, as porting of the 4.3-beta editor changes is yet to be completed.