Shapes not rendering in builds (investigation megathread)
sometimes Shapes doesn't render in builds, and as far as I can tell, this is caused by Unity excluding GPU instancing variants of Shapes shaders
1. Unity excluded Shapes shaders from the build (most likely cause)
Unity excludes unused shaders from builds, but can sometimes get this wrong, and this seems to affect instancing variants of shaders in particular, which often leads to Shapes working fine if you only draw one shape, but as soon as you draw multiple in a row, instancing kicks in, and the shader fails to load, and nothing is rendered. Sometimes, it can also be caused by unity messing up in-place update of assets, like when updating Shapes
Fix 1A: Go to Project Settings > Graphics > Instancing Variants, and set it to "Keep All". This might fix it on its own, and you might not need to do fix 1B
Fix 1B: Go to Project Settings > Graphics > Always included shaders, and then add the shaders you use in Shapes. You'll find the shaders Shapes uses in its folder, named after the shape type, split according to which blend mode they are using. If you're shipping to mobile, it might be good to only add the ones you actually use to reduce the build size, but if you're developing for desktop, you can probably just shove all Shapes shaders in there without any big issue
2. Unity corrupted your Shapes install (somewhat unlikely)
Unity sometimes has issues updating asset store packages in-place, leading to corrupt asset states
Fix 2: Do a clean reinstall of Shapes, and see if you still have issues. This is very important to do before reporting any bugs in general. The package manager and Unity in general often struggle to update assets cleanly, so you may have cached files in a broken state, which often leads to weird issues like this. We have multiple reports [1] [2] [3] of clean reinstalls solving this issue
3. Your platform doesn't support GPU instancing (unlikely)
You can test whether it does using SystemInfo.supportsInstancing.
Fix 3: If your platform doesn't support GPU instancing, you need to disable GPU instancing in the Shapes settings window, which means drawing multiple shapes in a row won't be able to get the performance benefits of instancing ;-;
Still not working?
I would start by testing a few things to investigate further:
- Please check for any build or runtime logs for warnings/errors related to Shapes or shaders
- If you are using immediate mode rendering in Shapes, try disabling immediate mode GPU instancing in the Shapes settings window, and then see if it works. If it works after this, we know that it's related to GPU instancing. If it still doesn't work, then let me know!
- Again, make sure all shader instancing variants of Shapes shaders are included in your graphics settings (see Fix 1B above). Unity can't predict which shaders you will use in immediate mode, and so it will sometimes strip them from builds
other than that I'm at as much of a loss as you are - I've implemented instancing support the way one should, it works just fine on many platforms, including iOS and Android for many, so I don't know why it seems to fail in some specific cases. There might be some hidden setting somewhere that disables GPU instancing elsewhere, though that's something I wouldn't know of
Do let me know if you find something out that might help us resolve this!
Reported issues:
Target platform | Unity version | Render Pipeline | Instancing off works? |
---|---|---|---|
iOS (iPhone 13 pro) | 2020.3.24 | URP | yes |
Android/iOS | 2021.2.0 & 2020.3.5 | URP | yes |
M1 mac mini | ? | ? | ? |
WebGL in chrome | 2019 & 2020 | Built-in | yes |
WebGL 2.0 | 2019.4.12 | ? | ? |
WebGL 2.0 | 2019.3.0 2020.1.3 2020.1.11 2020.2.13 | Built-in | ? |
Editor | 2021.2.0 | Built-in | yes |
Editor | 2021.1.10 | URP | yes |
That would be my go to, I'm not sure how to verify it in builds I'm afraid :c