A mesh with a Sprite lit/unlit material becomes invisible after applying a MaterialPropertyBlock to its MeshRenderer. Before applying the MaterialPropertyBlock, the mesh is visible. This is not a specific case, but is consistently reproducible with any mesh whose material uses the Sprite shader. This happens in both the Scene and Game views. I use Unity 6 (6000.30f1), URP 2D.
I have simplified the situation as much as possible and narrowed it down to a simple example where I create any mesh (for example, one of the default available meshes), then apply the URP/2D/Sprite Lit material to it and use very simple code that utilizes a MaterialPropertyBlock.
var materialPropertyBlock = new MaterialPropertyBlock();
var renderer = GetComponent<MeshRenderer>();
renderer.GetPropertyBlock(materialPropertyBlock);
renderer.SetPropertyBlock(materialPropertyBlock);
The result is always the same—the mesh becomes invisible. Although its geometry (if wireframe view is enabled) is still present. Moreover, if I do use a non-empty MaterialPropertyBlock with set values, they are applied perfectly, and the material inspector shows that they have been applied. Nevertheless, the mesh still becomes invisible.
The issue can be resolved by switching the base material from Sprite Lit/Unlit to Lit/Unlit. However, this workaround disables the use of 2D lighting, making it unsuitable for my needs.
Is this a bug, or does it indicate that MeshRenderer cannot be used with MaterialPropertyBlock in a 2D game with Sprite-based materials due to some engine limitations? Any insights would be greatly appreciated!
An important note: as long as the MaterialPropertyBlock is not applied to the MeshRenderer, everything displays correctly, and 2D lighting works perfectly.
Karumi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.