Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[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;