• RuntimesUnity
  • SpineAtlasAsset.CreateRuntimeInstance method with blend materials

I am working in a project where I need to create the Spine asset in runtime.
I'm using the method SpineAtlasAsset.CreateRuntimeInstance and it's working!
But, the spine assets that I have are using blending materials for some parts of the spine skeleton.

I don't know how can I create the AtlasAsset with multiple materials:
My current code is:

 _atlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasTextAsset, atlasTextures, atlasSourceMaterial, true);
        _skeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJsonTextAsset, _atlasAsset, true);
        _skeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(_skeletonDataAsset);
        _skeleton = _skeletonAnimation.Skeleton;

Could someone help me in How can I add the multiply material on this data asset to create my character?

I found the BlendModeMaterials property and tried to play with, but didn't worked yet:

    _skeletonDataAsset.blendModeMaterials.RequiresBlendModeMaterials = true;
    _skeletonDataAsset.blendModeMaterials.applyAdditiveMaterial = true;
    _skeletonDataAsset.isUpgradingBlendModeMaterials = true;
    
    List<BlendModeMaterials.ReplacementMaterial> multiplyMaterials = new List<BlendModeMaterials.ReplacementMaterial>();
    foreach (AtlasPage page in  _atlasAsset.GetAtlas().Pages)
    {
        var repMaterial = new BlendModeMaterials.ReplacementMaterial();
        repMaterial.pageName = page.name;
        repMaterial.material = _atlasSourceMultiplyMaterial;
        multiplyMaterials.Add(repMaterial);
    }

    _skeletonDataAsset.blendModeMaterials.multiplyMaterials = multiplyMaterials;`

@PedroRossa Sorry for the troubles, instantiation with blend mode materials seems to be missing from the API currently. Until we get to implement support officially, could you please check whether the following line is called in your executed code:

blendModeMaterials.ApplyMaterials(loadedSkeletonData);

It's normally called implicitly by SkeletonDataAsset.GetSkeletonData() here, but it might not be called in your code. This method call is necessary to update the material references at the respective slots.

Hey Harald, thank you for your answer.
So, I saw that the GetSkeletonData call this applyMaterials, but it's not blending correctly.

There is my runtime code to generate the asset:

_atlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasTextAsset, atlasTextures, atlasSourceMaterial, true);
_skeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJsonTextAsset, _atlasAsset, true);
_skeletonDataAsset.blendModeMaterials.RequiresBlendModeMaterials = true;
_skeletonDataAsset.blendModeMaterials.applyAdditiveMaterial = true;
_skeletonDataAsset.isUpgradingBlendModeMaterials = true;

    List<BlendModeMaterials.ReplacementMaterial> multiplyMaterials = new List<BlendModeMaterials.ReplacementMaterial>();
    foreach (AtlasPage page in  _atlasAsset.GetAtlas().Pages)
    {
        var repMaterial = new BlendModeMaterials.ReplacementMaterial();
        repMaterial.pageName = page.name;
        repMaterial.material = _atlasSourceMultiplyMaterial;
        multiplyMaterials.Add(repMaterial);
    }
    
    _skeletonDataAsset.blendModeMaterials.multiplyMaterials = multiplyMaterials;
    var sd = _skeletonDataAsset.GetSkeletonData(true);
    _skeletonDataAsset.blendModeMaterials.ApplyMaterials(sd);
    
    
    _skeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(_skeletonDataAsset);
    _skeleton = _skeletonAnimation.Skeleton;
    
    _skeletonAnimation.gameObject.name = "Runtime Spine";
    _skeletonAnimation.AnimationName = "idle";
    _skeletonAnimation.gameObject.transform.SetParent(transform);
    _skeletonAnimation.gameObject.transform.localScale = Vector3.one;
    _skeletonAnimation.transform.localPosition = Vector3.zero;`

And the result spine character with weird blending:

There is something wrong on my code?

I found at the documentation about material configurations too:
And I check and looks like everything is correct:
Unity texture importer:

Unity Spine Settings:

The result with these configurations and the runtime code (without add blending material by hand):
_atlasAsset = SpineAtlasAsset.CreateRuntimeInstance(atlasTextAsset, atlasTextures, atlasSourceMaterial, true);
_skeletonDataAsset = SkeletonDataAsset.CreateRuntimeInstance(skeletonJsonTextAsset, _atlasAsset, true);
_skeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(_skeletonDataAsset);
_skeleton = _skeletonAnimation.Skeleton;

    _skeletonAnimation.gameObject.name = "Runtime Spine";
    _skeletonAnimation.AnimationName = "idle";
    _skeletonAnimation.gameObject.transform.SetParent(transform);
    _skeletonAnimation.gameObject.transform.localScale = Vector3.one;
    _skeletonAnimation.transform.localPosition = Vector3.zero;

    _skeletonAnimation.Initialize(false);
    _skeleton.SetSlotsToSetupPose();
    _skeletonAnimation.AnimationState.Apply(_skeleton);

Is generating the dark borders:

Ah, the border lines are solved!
I discovered that one of the material references that I had was using the wrong setting.
After adjust it, solved the issue with the blending!

For other people that could go over this problem, read this on documentation:
Advanced- Premultiplied-vs-Straight-Alpha-Import

    @PedroRossa Sorry to hear that BlendModeMaterials.ApplyMaterials() didn't resolve your issue.

    PedroRossa Ah, the border lines are solved!
    I discovered that one of the material references that I had was using the wrong setting.
    After adjust it, solved the issue with the blending!

    Glad to hear you've figured it out, thanks for letting us know!