Search Unity

Shadows for Instantiated Asset Bundle Objects?

Discussion in 'Editor & General Support' started by HaruThePotato, May 23, 2017.

  1. HaruThePotato

    HaruThePotato

    Joined:
    May 24, 2016
    Posts:
    2
    I'm currently working on a project and my next goal is to be able to instantiate an object from asset bundle during runtime, I managed to reach that far but I noticed that my instantiated object from asset bundle doesn't have any shadows. I tried dragging out the exact object that's in my assets folder and it works fine, even instantiating the object in my assets folder seems good, but the problem occurs when I try to instantiate it from assets bundle.

    I'm not really sure whether I'm doing something wrong, or is this a Unity bug.

    The plane and cube with the shadow are dragged from the asset bundle whilst the objects without shadows are instantiated from the asset bundle.
    https://i.stack.imgur.com/ka97d.png

    Thanks a lot for taking the time to read!
     
  2. HaruThePotato

    HaruThePotato

    Joined:
    May 24, 2016
    Posts:
    2
    Seems like instantiating through assetbundles did something to it's shader, I used this code to re-set all of the shaders in the scene and it worked for me.

    Shader standardShader;

    void Start() {
    standardShader = Shader.Find("Standard");
    }

    void changeShader() // because shadow for assetbundle is cucked.
    {
    var renderers = FindObjectsOfType<Renderer>() as Renderer[];
    for (int i = 0; i < renderers.Length; i++)
    renderers.material.shader = standardShader;
    }

    and called it after all of the instantiating is done.
     
  3. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    96
    the same in Unity 2017.2
    BUG no doubt - problem with shadows...
     
  4. TheTortilla

    TheTortilla

    Joined:
    Nov 25, 2013
    Posts:
    38
    Same in Unity 2021.3.11f1