Skip to content

Commit

Permalink
fix: graphic.materialForRendering always returns different material
Browse files Browse the repository at this point in the history
close #103
  • Loading branch information
mob-sakai committed Sep 27, 2020
1 parent 97e5a21 commit 3f6acec
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Packages/SoftMaskForUGUI/Scripts/SoftMaskable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
{
_softMask = null;

// Unregister the previous material
MaterialCache.Unregister(_effectMaterialHash);
_effectMaterialHash = k_InvalidHash;

// If this component is disabled, the material is returned as is.
if (!isActiveAndEnabled) return baseMaterial;

// If the parents do not have a soft mask component, the material is returned as is.
if (!softMask) return baseMaterial;
if (!isActiveAndEnabled || !softMask)
{
MaterialCache.Unregister(_effectMaterialHash);
_effectMaterialHash = k_InvalidHash;
return baseMaterial;
}

// Generate soft maskable material.
var previousHash = _effectMaterialHash;
_effectMaterialHash = new Hash128(
(uint) baseMaterial.GetInstanceID(),
(uint) softMask.GetInstanceID(),
Expand Down Expand Up @@ -145,6 +145,9 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
));
});

// Unregister the previous material.
MaterialCache.Unregister(previousHash);

return modifiedMaterial;
}

Expand Down

0 comments on commit 3f6acec

Please sign in to comment.