In unity editor (5.4.3), I have a scene where I switch an objects materials at runtime twice (2 seconds apart). The first time I run this after opening Unity up I get a huge fps drop with both switches when it occurs. Thereafter the fps remains fine and constant every subsequent time I run the scene. Does anyone know how to prevent this, I was thinking of doing a material swap at startup as a “warmer” but it concerns me that the fps drops both times in the initial runthrough (the swaps occur about 2 seconds apart). Just not sure what is causing it or if there is a fix. I thought maybe it has to do with gc allocation? If anyone else ran across this issue before and has some tips please let me know!
bump for any helpful good samaritans
Does this happen in the build, or just the editor? It could be that shaders in the editor are not pre-compiled, and this may not happen in the build.
GC allocation will not cause an FPS drop unless you’re doing a huge allocation. GC deallocation will cause an FPS drop but not right away, it will occur when the next GC run happens. Generally you’ll see GC problems as random dropped frames not related to things that are happening right now.
Thanks UziMonkey! I was just able to finish building and tested it and the problem didn’t seem to pop up. So I guess its like you said that the shaders were not pre-compiled in the editor. Many thanks!
One way to test it is to open up the task manager. When Unity compiles a shader, it starts a “Unity Shader Compiler” process, which would appear in the task manager.
I will take a look at this and see if i can see it before it disappears, thanks!