I’ve just noticed that all materials in my project show this warning. I can’t think of anything weird I’m doing. Most of my objects are 2D sprites with the original Sprites-Default material. Some sprites have a particle shader, which is not strictly speaking made for the Sprite Renderer, but still works fine.
When I create a new empty sprite, the Sprites-Default material gets assigned, everything is normal. When I now add one of my sprite assets to the Sprite Renderer, the warning appears in the material inspector.
I am not using the MaterialBlock API in code and I’m not animating the materials via the Animator. At least, not that I know of.
This is because the Sprite Render uses MaterialPropertyBlock to assign the sprite texture into the material (shader). This is why you are able to use different sprites on Sprite Renderer, while just having a single material.
The default sprite shader has the tag which is to hide the _MainTex property on material, so you are not able to see the “texture slot” on the material.
Other shaders like Particle ones are having _MainTex property visible, but once apply to Sprite Renderer, the “texture slot” on Particle materials will have no effect.
Thanks, that does sound logical. So it’s not a real issue. Still, it is weird, that it shows as a warning, always looks like something went wrong.
I think it makes a lot of sense, that the warning shows, when using the regular particle material, since like you explained, the _MainTex slot will be overridden by the sprite, but the warning also shows on a regular sprite with the default sprite material, where there’s no ambiguity between which texture is used.
Doesn’t matter. MaterialPropertyBlock is something that works with any renderer(perhaps short of CanvasRenderer,not 100% sure there). Just so happened that OP was using a SpriteRenderer.
Are you trying to change the texture through code as well as through animation clip?
Read this to understand MaterialPropertyBlocks better. Using them will make rendering faster and it’s something that’s used under the hood in some parts like animations,by default.
It’s not an error then.As you can see from the link in my previous response, this is something that’s there as a warning. Since you’re modifying something in an animation clip, it warns you that you basically can’t modify that property in code. If I remember correctly, trying to change the value through code will compile and play without errors, but since a value is being changed through animation clip it has higher priority so any changes through code are going to be overritten by the animation clip.
Yes ,unless I’m misunderstanding something,you should. MaterialPropertyBlocks is just what’s used to store values in certain cases when animating stuff.