Inconsistent Sprite Atlas shader behaviour in Editor?

I have a custom outline shader graph that takes a sprite’s textureRect as an input property. My sprites are all in sprite atlases (not tightly packed), so the textureRect should always point to the rect in the atlas. Whenever I go into play mode in editor, this is true most of the times, but in other times, the editor assumes the sprite’s texture is the original png texture instead of the sprite atlas, and the _MainTex property of my material will point to the original texture, leading to incorrect calculations and breaking the shader.

The change from correct to incorrect sprite texture is seemingly random, but I wanted to ask if this is a bug or if I’m missing something and there’s a way to have it always point to the correct sprite atlas texture.

As long as the SpriteAtlas does not get repacked (due to addition of new sprite, removal of sprite or any change that cuases SpriteAtlas to repack), the rect should remain consistent.
Please ensure that the Max texture size remains the same on all the platforms (as some formats may have limitations).

If this is not the case, please file a bug report. Will take a look asap.

Hi, I already had the same problem and found that when starting playmode while being in a prefab just ignore the sprite atlas mode and uses textures instead of SpriteAtlases. Maybe it’s the same thing for you.

That’s definitely possible! Will test it out later.

This could have very well been it! I can’t seem to replicate it now which I guess is a good thing hah, but yeah it may not be consistent behaviour. Thanks for letting me know I may have never been able to figure it out otherwise!

Happy to help, it took me hours to find out this one xD.
Note that there are ways to have shaders looking the same with or without sprite atlas by grabbing the sprite UV.
You can read more in this thread: https://discussions.unity.com/t/shader-graph-getting-local-sprite-uv-from-sprite-sheet/785133/29