Search Unity

[Resolved] How to Load new Custom Shaders

Discussion in 'Asset Bundles' started by SirDevin, Nov 28, 2018.

  1. SirDevin

    SirDevin

    Joined:
    Oct 10, 2014
    Posts:
    30
    I am trying to load new custom shaders into an already compiled game with Asset Bundles at runtime. Is this possible or am I wasting my time here.

    Example: Create an assetbundle with just a shader in it. Load said shader into compiled game making sure build targets are consistent. Instantiate a primitive and and assign it the new shader.
     
  2. SirDevin

    SirDevin

    Joined:
    Oct 10, 2014
    Posts:
    30
    I resolved the issue. It doesn't seem to load the shader in a way that can be found with Shader.Find("MyShader"). You have to load the instance of the shader in a variable and set it to the object you wish to change.
    Code (CSharp):
    1.  
    2.         var shader = shaderBundle.LoadAsset("UnlitTest");
    3.  
    4.         GameObject testObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
    5.         Renderer rend = testObj.GetComponent<Renderer>();
    6.         rend.material.shader = (Shader)shader;
     
    Silas-VuCity likes this.