Hello,
I have a pretty good implementation of textures on entities that are affected by a status effect. I have a base sprite (8x8) that is scaled up using the Repeat scaling, with Tiled Slicing on the Sprite Renderer. This means that that 8x8 pattern is repeated for whatever scale it is used on. I then scale the tiling up to match the rectangular size of the entity. After that (because my entities are not rectangles), I set the Status Effect’s Sprite Mask’s Sprite to be the Sprite of the entity it is affecting. I also set the Status Effect’s transform’s parent to be the transform of the entity being affected.
This works really well - with two exceptions. 1) When multiple entities of the same type (i.e., they share the same Sprite) are close and they both share the same Status Effect, the status effect from the other entity will “bleed through” over to the other entity. While this may not seem like an issue, as they have the same effect, I allow the stacking of Status Effects, and they have a low individual alpha, as to increase the visual impact as more stacks are accrued. This means a clear rectangle can be seen where the two effects intersect. My assumption here is that the two Status Effect’s Sprite Mask’s point to the same Sprite, meaning that they effectively have the same Sprite Mask, so when a new Sprite Mask enters its rectangle, it is shown there too.
The smaller issue being that the effect will overlay on anything between their two layers. Because the Status Effect and Entity are separate GameObjects, they must have some form of layer sorting. My current method is placing it one Sorting Layer above the entity that’s being affected, but when multiple entities of the same type are close (and intersecting), the Status Effects will overlay. This is less of a concern than the previous issue.
My current idea is to Create a new Sprite using the same data as the Entity’s Sprite, but I fear this will devour memory for no reason besides creating a new pointer - as the only reason I am creating the sprite is to tell Unity’s masking system “these are not using the same mask”. To clarify, I just want the same shaped mask, but not the same mask.
I was wondering if somebody could give me some clarification as to how SpriteMasks work in the background so I can understand a bit more about what’s going on here.