maru7

你好,我在Unity中使用SkeletonGraphic组件时遇到了这样的问题,
Hello,I have a trouble when using SkeletonGraphic component in Unity,

它的Spine模型在UnityEditor中显示正常,而在Build后运行时出现了贴图丢失的问题(PC平台),如下图:
the skeleton cannot displaying correctly after build and run,but it works right in UnityEditor.

UnityEditor中:
Running in UnityEditor:
TIM截图20200626065521.png


Build后运行时:
Runing after build:
TIM截图20200626065539.png



调用代码为:
The coding is:
public static void SetSpineAvatar(UnitSpineData sdata)
{
var obj = CreateSpineAvatarPrefab(); // Instantiate perfab
var sg = obj.GetComponent<SkeletonGraphic>();

SkeletonDataAsset sda = CreateSkeletonData(sdata.ModelName); // Create SkeletonDataAsset
sg.skeletonDataAsset = sda;
sg.Initialize(true);

var dic = ChangeSlotAttachments(sdata, sg.Skeleton); // Change attachments

//Repack skin
RepackSkeletonSkin(sg.Skeleton, sg.skeletonDataAsset, out Material runtimeMaterial, out Texture2D runtimeAtlas);
sg.material = runtimeMaterial;
sg.material.shader = Shader.Find("Spine/SkeletonGraphic");
sg.OverrideTexture = runtimeAtlas;
sg.AnimationState.SetAnimation(0, "idle", true);
}

private static void RepackSkeletonSkin(Skeleton skeleton, SkeletonDataAsset dataAsset, out Material runtimeMaterial, out Texture2D runtimeAtlas)
{
var repackedSkin = new Skin("repacked skin");
repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);
repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", dataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas);
skeleton.SetSkin(repackedSkin);
skeleton.SetSlotsToSetupPose();
}
我发现在UnityEditor中重新打包后的皮肤材质贴图如下:
I found the runtime material and altas of repacked skin is a image like this in UnityEditor:
TIM截图20200626093142.png


但在Build后运行的程序中变成了这样:
But it cannot work correctly after the project build:
TIM截图20200626093212.png


如果我移除重新打包皮肤的代码,SkeletonGraphic就可以加载贴图,但是你懂的……
If I remove the RepackSkeletonSkin code,SkeletonGraphic component can load texture instead of white square,but you know SkeletonGraphic component supports only a single atlas texture...
TIM截图20200626081611.png



在UnityEditor中显示的SkeletonGraphic和Shader的参数如下:
The properties of SkeletonGraphic component and its shader (in UnityEditor):
TIM截图20200626072514.png

TIM截图20200626072501.png



同样的Spine模型在使用SkeletonAnimation组件时无论是UnityEditor中或是Build后都显示正常。
The same skeleton can displaying correctly when using SkeletonAnimation component after build,but I need use it in UI with SkeletonGraphic component.

已经检查过Unity打包时引入的Shader设置,但问题没有得到解决。
I have checked the "Always included shaders" setting in "Built-in shader settings",but the problem was not solved.


我的Unity版本是2019.3.14f1,Spine版本是spine-unity-3.8-2019-08-20.unitypackage
My unity version is 2019.3.14f1, spine runtime version is spine-unity-3.8-2019-08-20.unitypackage.

---

好的吧,我很高兴地发现它只是出现了配置问题,在打包时需要把所有用到的材质设置为可读写的。
unity的一些编辑器和实际打包运行之间的没有提示的小细节差异挺搞人心态……
You do not have the required permissions to view the files attached to this post.
maru7
  • Posts: 1

Harald

感谢您的详细撰写。 很高兴您可以解决问题。 由于自动翻译说“材料需要可读/可写”-我假设您的意思是纹理需要启用“读/写”功能,对吗?
Thanks for the detailled writeup. Glad you could resolve the problem. Since automatic translation said "the Materials need to be readable / writable" - I assume you mean the Textures need to have Read/Write Enabled, right?
maru7 wrote:如果我移除重新打包皮肤的代码,SkeletonGraphic就可以加载贴图,但是你懂的……
[..] but you know SkeletonGraphic component supports only a single atlas texture...
SkeletonGraphic不再有单一材质的限制,你现在可以在Inspector中启用Advanced - Multiple CanvasRenderers
spine-unity Runtime Documentation: SkeletonGraphic Component
当然,如果可能的话,还是使用单一的图集纹理比较好。

SkeletonGraphic no longer has the single material limitation, you can enable Advanced - Multiple CanvasRenderers in the Inspector now:
spine-unity Runtime Documentation: SkeletonGraphic Component
Still, of course it is better to use a single atlas texture if possible.
User avatar
Harald

Harri
  • Posts: 1944


Return to 中国Spine用户