Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Broken shaders when loading from AssetBundle

Discussion in 'Editor & General Support' started by rile-s, Jan 27, 2021.

  1. rile-s

    rile-s

    Joined:
    Sep 18, 2019
    Posts:
    26
    I'm working on a system for loading scenes that have been exported from another project. When a scene is loaded from an AssetBundle, the materials have a weird artifact that goes away as objects with materials not in said AssetBundle are rendered over it. This happens in both the Game View and the Scene View.
    Screenshot 2021-01-25 180808.png Screenshot 2021-01-25 180956.png
    I will try to provide any information needed to fix this.
    Thanks in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Code such as scripts and shaders needs to be in your base project.

    If you don't reference the shader in your base project, it will be dropped / stripped at build time.

    You can get around this by referencing all the shaders you want in the base project.

    Just make a material using that shader and put it in a folder under Resources/
     
  3. rile-s

    rile-s

    Joined:
    Sep 18, 2019
    Posts:
    26
    The shader used in those screenshots is referenced and used in the base project. So, I do not believe that is the issue. But placing a material with the shader in resources did not solve the issue.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Interesting. The only other thought is, are you building the asset bundle for the correct target architecture? Usually if you don't it doesn't work at all, but I know for some simple cases it would work and shaders would borked.

    Re-reading the above, I realize that I've never made asset bundles for another game, always kept it same-game. I actually kinda thought that would be necessary given the way Unity maps GUIDs for everything.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
  6. rile-s

    rile-s

    Joined:
    Sep 18, 2019
    Posts:
    26
    Hmm, looks interesting. I will try this real soon, I hope this fixes it.
     
  7. rile-s

    rile-s

    Joined:
    Sep 18, 2019
    Posts:
    26
    It actually worked! I am not so good at using Google. Thank you so much. :)
     
    Kurt-Dekker likes this.
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Cool! What was it you did, match up the meta files? Just curious and for future reference if anyone finds this thread.
     
  9. rile-s

    rile-s

    Joined:
    Sep 18, 2019
    Posts:
    26
    I just copied the whole project over and placed my scripts in. I do believe it was the meta files that fixed it.
     
    Kurt-Dekker likes this.