Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Shader.SetGlobalFloatArray requires restart to change array size?

Discussion in '5.4 Beta' started by Devilbox-Games, May 12, 2016.

  1. Devilbox-Games

    Devilbox-Games

    Joined:
    Jul 3, 2012
    Posts:
    205
    I upgraded to the 5.4 beta when I saw it had proper support for array properties in shaders as I need it for an effect I'm working on. After a bit of playing around with it, I noticed a huge performance drop in when setting the array properties, which turned out to be due to the following warning message being sent to the console every time it sets an array property:

    Code (csharp):
    1. Property (_SplatSize) exceeds previous array size (50 vs 5). Cap to previous size.
    This stumped me all of yesterday because the size of the array had not been set before Shader.SetGlobalFloatArray was called in OnPostRender, so I assumed there shouldn't be a way of it being set to 5 initially. However, when I started Unity this morning it did not throw the warning message.

    After some further playing around I discovered what was happening: the first time you run code which calls Shader.SetGlobalFloatArray will set the size and then any subsequent code changes which make the array increase in size will throw the warning message and cap the array size even if the new size is a constant value in your code.

    Is this intended functionality or a bug I should report? And if it is intended, is there a way of forcing Unity to clear the properties instead of having to restart Unity?