Shapes not rendering in builds (investigation megathread)

Avatar
  • updated

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:

    1. Please check for any build or runtime logs for warnings/errors related to Shapes or shaders
    2. 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!
    3. 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 platformUnity versionRender PipelineInstancing off works?
    iOS (iPhone 13 pro)2020.3.24URPyes
    Android/iOS2021.2.0 & 2020.3.5URPyes
    M1 mac mini???
    WebGL in chrome2019 & 2020Built-inyes
    WebGL 2.02019.4.12??
    WebGL 2.02019.3.0
    2020.1.3
    2020.1.11
    2020.2.13
    Built-in?
    Editor2021.2.0Built-inyes
    Editor2021.1.10URPyes

    Reporting a bug? please specify Unity version:
    Reporting a bug? please specify Shapes version:
    Reporting a bug? please specify Render Pipeline:
    Built-in render pipeline
    Avatar
    peter roth

    The clean install worked for me. WebGL Build.
    -Flat
    2DLines were not working unless GPU instancing was turned off. --> After a clean install, they do!

    -I did a clean install according to the instructions (more than just deleting and reinstalling the shapes package must delete Library to force a reimport...see Freya's instructions: 

    Avatar
    Trevor G

    Here's my saga with a happy ending...(using 2021.3.6f1 (LTS) and Shapes 4.3.1).

    1.  Everything worked in the Editor with GPU Instancing On (except Draw.Texture, single Texture would render, but if I called Draw.Texture twice, nothing would render)

    2. On Build, about half the Draw Commands worked (with and without GPU Instancing).  

    3. I deleted my ShaderCache and PlayerCache folders from Library as suggested in an earlier post.

    4. Now the Editor looked like how previous builds did (about half the lines being rendered).  However, with GPU instancing OFF, everything worked in the Editor AND Build (good enough).

    5.  I tried to do a clean install, but deleting the Library folder caused lots of problems in my project (elsewhere), so I backed off that.

    6.  I was randomly trying some things...In the Settings, I changed the "Local AA Quality" from HIGH to MEDIUM.  Now, everything renders correctly in Editor/Build with or without GPU Instancing.  YAY!

    7.  I also had an issue rendering textures...feeling lucky, I changed the "Quad Interpolation Quality" from MEDIUM to LOW and this fixed my Texture issue as well (In Editor And Build with and without GPU instancing. Double YAY!

    Hopefully there's something helpful in that chaos.

    Avatar
    edvard rutström
    Quote from Trevor G

    Here's my saga with a happy ending...(using 2021.3.6f1 (LTS) and Shapes 4.3.1).

    1.  Everything worked in the Editor with GPU Instancing On (except Draw.Texture, single Texture would render, but if I called Draw.Texture twice, nothing would render)

    2. On Build, about half the Draw Commands worked (with and without GPU Instancing).  

    3. I deleted my ShaderCache and PlayerCache folders from Library as suggested in an earlier post.

    4. Now the Editor looked like how previous builds did (about half the lines being rendered).  However, with GPU instancing OFF, everything worked in the Editor AND Build (good enough).

    5.  I tried to do a clean install, but deleting the Library folder caused lots of problems in my project (elsewhere), so I backed off that.

    6.  I was randomly trying some things...In the Settings, I changed the "Local AA Quality" from HIGH to MEDIUM.  Now, everything renders correctly in Editor/Build with or without GPU Instancing.  YAY!

    7.  I also had an issue rendering textures...feeling lucky, I changed the "Quad Interpolation Quality" from MEDIUM to LOW and this fixed my Texture issue as well (In Editor And Build with and without GPU instancing. Double YAY!

    Hopefully there's something helpful in that chaos.

    I can confirm that 6. above helped us with the GPU instancing issue. GPU instancing is working properly in the rest of the game, so this might be a lead?

    Best of luck, and thanks for a really great plugin!

    Edit: this actually didn't seem to fix all the issues, but Sergeys comment below helped!

    Avatar
    Sergey Khanin

    Unity 2022.3.19f1

    Its works for me:
    Project settings -> Graphics -> Instancing Variants - Keep All 

    Image 822



    GraphicsSettings.asset

      m_InstancingStripping: 2
    Avatar
    edvard rutström

    Sergeys comment seems to have fixed the issue. Seems like we were stripping instancing variants, which made Shapes not work in builds (duh). Thanks for the help Sergey! 

    Avatar
    Jim Chan

    I have problem with running example "FPS HUD" and "IMCanvas" on device.And finally found the following steps work for me:

    1. On Project Settings -> Graphics -> Shader Stripping -> Instancing Variants, set to "Keep all".

    2. On Shape Settings -> Shader Settings -> Quad interpolation quality, set to "Low". (Thanks to Edvard Rutström for the suggestion)

    3. Click "Apply shader settings" button.

    4. Click "Regenerate Shaders & Materials" button.

    Environment:

    Unity: 2022.3.24 Shapes version 4.3.1

    Render pipeline: URP 14.0.10

    Device: Google Pixel 6 (Android)

    Avatar
    Anne

    I'm encountering issues on specific devices like the iPad Pro (10.5) and some Android models.

    None of the previously mentioned solutions have resolved the problem. Through investigation, I've discovered that:

    When shapes are children of a Canvas set to "Canvas - Camera Space," only rectangles render correctly in the build. However, if the shapes are not children of the canvas, they render correctly.

    Everything functions properly in Unity version 2021.3.16f1, but I haven't managed to get it to work in newer versions. Additionally, it works as expected on all other devices I have tested and within the Editor across all Unity versions I've tested so far. This issue was tested with an empty project.

    Any clues on what could be the cause? I'd hate to remove Shapes just because a few models are experiencing issues.

    Avatar
    Freya Holmér creator
    Quote from Anne

    I'm encountering issues on specific devices like the iPad Pro (10.5) and some Android models.

    None of the previously mentioned solutions have resolved the problem. Through investigation, I've discovered that:

    When shapes are children of a Canvas set to "Canvas - Camera Space," only rectangles render correctly in the build. However, if the shapes are not children of the canvas, they render correctly.

    Everything functions properly in Unity version 2021.3.16f1, but I haven't managed to get it to work in newer versions. Additionally, it works as expected on all other devices I have tested and within the Editor across all Unity versions I've tested so far. This issue was tested with an empty project.

    Any clues on what could be the cause? I'd hate to remove Shapes just because a few models are experiencing issues.

    I've updated the first post/OP with some more steps! Specifically I would recommend trying the 1A and 1B fixes!

    Avatar
    Andy

    FYI Volumetric3D lines were not drawing for me in WebGL, had to turn off GPU Instancing. 

    (Unity 2022 LTS URP, Windows11, Edge, Nvidia beast etc!)

    Perhaps could be automatic if determined to be incompatible with WebGL? But seems that may not be clear...

    Avatar
    oliver andreas thunæs

    Adding to this.

    Target platform: iOS 18 iPhone 15 Pro

    Unity version: 6000.0.23f1 (although this also happened in Unity 2022)

    Shapes version: 4.4.0 (this also happened in 4.3.*)

    Works with GPU instancing OFF: yes.

    And it's only affecting a specific line renderer.

    My project is setup in such a way that I'm pretty much only using immediate mode. Everything is rendered from a central script which calls render methods on a list of objects that each handle their own rendering.


    Anything that's using Draw.Line() does not show up in a build if GPU instancing is enabled. Everything else renders correctly.

    I've tried to include the shaders for 2D and 3D lines, as well as setting instancing variants to Keep All. I've done a complete re-install of shapes as per the instructions from that post on this forum.

    Avatar
    Freya Holmér creator
    Quote from oliver andreas thunæs

    Adding to this.

    Target platform: iOS 18 iPhone 15 Pro

    Unity version: 6000.0.23f1 (although this also happened in Unity 2022)

    Shapes version: 4.4.0 (this also happened in 4.3.*)

    Works with GPU instancing OFF: yes.

    And it's only affecting a specific line renderer.

    My project is setup in such a way that I'm pretty much only using immediate mode. Everything is rendered from a central script which calls render methods on a list of objects that each handle their own rendering.


    Anything that's using Draw.Line() does not show up in a build if GPU instancing is enabled. Everything else renders correctly.

    I've tried to include the shaders for 2D and 3D lines, as well as setting instancing variants to Keep All. I've done a complete re-install of shapes as per the instructions from that post on this forum.

    any relevant errors/warnings on build or at runtime? also, what happens if you include a dummy mesh renderer in the main scene, that uses the instanced variant of the line shaders you're using?

    Avatar
    oliver andreas thunæs
    Quote from Freya Holmér

    any relevant errors/warnings on build or at runtime? also, what happens if you include a dummy mesh renderer in the main scene, that uses the instanced variant of the line shaders you're using?

    No relevant warnings/errors. Adding a dummy mesh didn't have an effect.

    Avatar
    Freya Holmér creator
    Quote from oliver andreas thunæs

    No relevant warnings/errors. Adding a dummy mesh didn't have an effect.

    hm, at that point I'd report a bug to unity!

    Avatar
    patrick cheng

    Hi, I'm having issues for shapes or lines to render in the editor in general.

    I'm on Unity 2022.3.39f1, using URP and having Android as the targeted platform.

    I wanted to experiment with Shape so I created a polygon and a line in the scene, but neither of them will show up.

    Image 862

    I get a warning in the inspector saying that "Note: this object is not GPU instanced due to custom depth/mask settings". So I hit reset, click on another game object, and click back on the object I just reset, and the warning is there again.

    Image 863

    The option of "Regenerate Shader & Material" did help for a second, when I clicked on this the shape will show up for a while, but then will disappear again eventually.

    Image 864

    Image 865


    One thing I did noticed is that whenever the shape is showing/rendering, the changelog in git shows that the _ColorMask in PolygonTransparent.mat gets set to 15 instead of -1. When the shape is not rendering this changelog goes away, so something is hard resetting this..?

    Avatar
    Freya Holmér creator
    Quote from patrick cheng

    Hi, I'm having issues for shapes or lines to render in the editor in general.

    I'm on Unity 2022.3.39f1, using URP and having Android as the targeted platform.

    I wanted to experiment with Shape so I created a polygon and a line in the scene, but neither of them will show up.

    Image 862

    I get a warning in the inspector saying that "Note: this object is not GPU instanced due to custom depth/mask settings". So I hit reset, click on another game object, and click back on the object I just reset, and the warning is there again.

    Image 863

    The option of "Regenerate Shader & Material" did help for a second, when I clicked on this the shape will show up for a while, but then will disappear again eventually.

    Image 864

    Image 865


    One thing I did noticed is that whenever the shape is showing/rendering, the changelog in git shows that the _ColorMask in PolygonTransparent.mat gets set to 15 instead of -1. When the shape is not rendering this changelog goes away, so something is hard resetting this..?

    that's, bizarre, 15 should be the default value, -1 is an invalid value


    are there any warnings in the console that says something about the shader that material is using?

    Avatar
    patrick cheng
    Quote from Freya Holmér

    that's, bizarre, 15 should be the default value, -1 is an invalid value


    are there any warnings in the console that says something about the shader that material is using?

    Unfortunately no, there is no warning nor errors popping up. 

    Avatar
    patrick cheng
    Quote from patrick cheng

    Hi, I'm having issues for shapes or lines to render in the editor in general.

    I'm on Unity 2022.3.39f1, using URP and having Android as the targeted platform.

    I wanted to experiment with Shape so I created a polygon and a line in the scene, but neither of them will show up.

    Image 862

    I get a warning in the inspector saying that "Note: this object is not GPU instanced due to custom depth/mask settings". So I hit reset, click on another game object, and click back on the object I just reset, and the warning is there again.

    Image 863

    The option of "Regenerate Shader & Material" did help for a second, when I clicked on this the shape will show up for a while, but then will disappear again eventually.

    Image 864

    Image 865


    One thing I did noticed is that whenever the shape is showing/rendering, the changelog in git shows that the _ColorMask in PolygonTransparent.mat gets set to 15 instead of -1. When the shape is not rendering this changelog goes away, so something is hard resetting this..?

    Adding an update to this issue, as it is now resolved.

    Apparently I had the Unity editor debug panel open, and it somehow might have conflict with the custom editor of Shape components, thus not being able to render any shapes for me.

    By simply closing the menu fixed the issue for me, just wanted to post this for future awareness. 

    Shapes and Unity editor debug menu can't be opened at the same time.

    Avatar
    Tiger Tang

    My immediate mode drawn shapes are randomly disappearing. I can confirm turning off GPU instancing works. I also set shader stripping to Keep All, but turning off GPU instancing is the one that did it. This is on a Meta Quest 3.

    Avatar
    ando

    Hello everyone, I've bumped into the same issue. Unfortunately I am using v4.1.3 (can't update because I lost access to the plugin in the Asset Store and Support is taking months to figure it out). Anyways, I've had issues with the rectangle using (border rounded corners) and the ring. The shapes wont render on an old iphone 6/7. Tried all the suggestion. Nothing worked.

    Eventually, I made a GameObject that had some odd scale x/y/z - 100/100/100. Obviously the sizes in Shapes had to compensate for that so I made them < 1 in radius and thickness. This fixed the issue and now I can see the disc.


    Hope this helps others.


    Freya, Shapes is great! Thank you for making it. I hope you find what's causing the rendering bug.