I used Material Property Blocks to alter a shader, and this works in the Scene view, but not in the Game view, leading to the material not changing and ‘sticking’ to whatever value it was. I can manually change it however, either in the inspector or a script and this will update in the Game view.
Property Blocks are a good optimisation tool. Is there any reason why they might not be working?
They should work if you’re using an up-to-date version of Unity and PolySpatial: for example, PolySpatial 1.2 and Unity 2022.3.27f1. For Unity versions lower than that, there’s an issue where the MeshRenderer won’t be dirtied (and thus won’t be transferred via PolySpatial) when the MaterialPropertyBlock is set. You can work around this by manually dirtying the Renderer via Unity.PolySpatial.PolySpatialObjectUtils.MarkDirty(Renderer) every time you set the MaterialPropertyBlock.
I can tell you, though, that using MaterialPropertyBlocks for visionOS won’t result in any kind of optimization. We are limited by RealityKit’s API, which doesn’t have a MaterialPropertyBlock equivalent. We handle MaterialPropertyBlocks behind the scenes by simply creating a new material with the affected properties.
At any rate, if you still have issues with MaterialPropertyBlocks, please file a bug report and let us know the incident number (IN-#####), so that we can look into it.
how do you determine what materials to duplicate? is it when any of the attached shader’s variants use material property blocks?
and does the the editor reflect this behaviour?
Whenever you use a MaterialPropertyBlock, we create a new material behind the scenes and configure it with the properties contained in the block. Setting the MaterialPropertyBlock again (on the next frame, for example) will reuse that new material instance, rather than creating a new one.
Yes; if you use the Debug PolySpatial GameObject Link component to find the GameObject created by PolySpatial to reflect the state of the original, you’ll see that it has a new material reference (different from the original object).
is it possible to get the list of the meshes polyspatial is drawing when on device? i’m seeing a discrepancy between the polyspatial camera draw count shows in editor and what instruments returns on device, where the device is reporting more than twice as many