Search Unity

Shader.Parse when loading assetbundles w/no shaders

Discussion in 'Scripting' started by RSpicer, Jan 25, 2018.

  1. RSpicer

    RSpicer

    Joined:
    Feb 27, 2014
    Posts:
    9
    I'm encountering a performance issue with 2017.2.0 and assetbundle loading. Hoping someone knows how to approach this:

    Our project loads a large number of assetbundles at runtime (bundles are terrain mesh tiles generated from a photogrammetry pipeline). Each bundle includes exactly two assets: 1) an imported mesh object (an OBJ file, as imported by the Editor) and 2) a single texture, for that object.

    (Not sure if relevant, but our pipeline uses multiple unity projects, so people working on the core renderer/game don't need to import every object that comes from the terrain pipeline -- so we have one project that generates bundles, and then our renderer/game as its own project. I can imagine that might confuse the dependency system..)

    Every time one of these assetbundles is loaded at runtime, the profiler indicates a significant CPU hit (eg: 100ms+) from Shader.Parse.

    This doesn't make sense to me, since 1) all meshassets are using the unmodified standard shader, only difference should be the texture (which should be a property of the material, not the shader)!

    Is there some way to convince the assetbundle pipeline to use the standard shader that's built in, rather than parsing it anew for each assetbundle?

    I've already read https://answers.unity.com/questions/1137952/about-shaders-included-in-assetbundles.html which is similar. In that case the asker solved the problem by creating a bundle including the shader and making sure all the bundles (the one containing the shader, and the ones containing the objects depending on it) were built simultaneously.

    In my case, I want to not include and load any additional shaders! I guess I could create a copy of the standard shader, use a script to make all my objects reference that shader, and then rebuild all bundles, plus a dummy bundle containing the copy of the standard shader. That seems hackish, though.
     
  2. banyango

    banyango

    Joined:
    Mar 31, 2014
    Posts:
    19
    Hey, Just wanted to reply to this.

    I'm on 5.6.4 and I was seeing the same issue.

    As a workaround, it seems to avoid the Shader.Parse if you don't include the MeshRenderer in your asset bundle, and then just add a mesh renderer component on the game object when you load it.

    Maybe not the best solution, as you lose all your material info on the asset bundle, but at least you don't get the performance penalty.
     
  3. CoderSi

    CoderSi

    Joined:
    Jun 1, 2018
    Posts:
    4
    We're also having this problem in 2017.4.4f1. As well as FindObjectsOfType causing the game to spike when unloading bundles. It seems Unity's bundle loading and unloading is not that well suited if you want to handle the loads/unloads during play and not behind a loading screen. Any advice here would be greatly appreciated! Thanks.