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

Line Renderer added at runtime - need to reference Default-Line shader in build

Discussion in 'Editor & General Support' started by JRW_WSP, Nov 15, 2019.

  1. JRW_WSP

    JRW_WSP

    Joined:
    Jun 26, 2017
    Posts:
    37
    Hi community

    I have a long running problem with Line Renderers that I've never really managed to resolve. Annoyingly when you create one at runtime using AddComponent<> it doesn't get the "Default-Line" material automatically and I can't work out the Shader path to assign a new material created using this shader.

    On top of that even if I could I don't think it would be included in the build automatically so would mess up anyway.

    Anyone know how I should go about this properly? Ideally I don't want to have to even create a material in my assets, it's a shame that new Line Renderers don't get the default-line shader be default when created. I want to use the default-line shader specifically as it has the functionality of picking up the Line Renderer color values...
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You can create the material at runtime.
    To make sure the shader is included i wold take a look at
    Shader Variant Collections
    https://docs.unity3d.com/Manual/OptimizingShaderLoadTime.html
    They can track what shader / variants are used and you can "force" include the needed variants in your build even if they are not "hard" referenced by any scene object.

    What rendering Pipeline are you using?
    In most cases particle shader should work for the line renderer.
    The particle system and the line renderer use both vertex colors for coloring the material.
     
  3. JRW_WSP

    JRW_WSP

    Joined:
    Jun 26, 2017
    Posts:
    37
    Interesting - I'll take a look. I'm using the Universal Render Pipeline currently. I've ended up for now exposing a shader variable and picking the UI/Unlit/Text shader in the inspector for now so the reference is picked up in the build. I woudl have like to know what the default-line corresponds to though - it doesn't show up in the picker, just seems to be in built in resources which I don't know how to reference. This is such a common problem when adding Line Renderers by code that it is somewhat maddening that I haven't worked this out for years!

    Anyway, as usual looks like I need to do more reading on the subject... thanks for the help.