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

URP / PLAY vs BUILD - terrains layers & details are pinks

Discussion in 'Universal Render Pipeline' started by merfolkjh, Aug 23, 2023.

  1. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    Hi,

    I have a working project in PLAY mode, but when i try BUILD mode, i have multiple problems with terrain.

    ----
    Context : All the terrains & terrains layers & details are generated at runtime, loading textures from the Resources folder.
    render = urp, for pc windows
    -----

    "Play mode" : everything is ok
    "Build mode": pink

    upload_2023-8-23_16-15-2.png

    ---

    issue #1 :
    the terrain layers are pink.



    Code (CSharp):
    1.  
    2.  
    3.        // init Code is globally something like this, for each "active biome"  - add a terrain layer to the current terrain
    4.  
    5.         List<TerrainLayer> listeTerrainLayers = new List<TerrainLayer>();
    6.         for (int i=0 ; i < TerrainSpawn.refBiomes.Count ; ++i) {
    7.             if (listeBiomesActifs[i] ) {
    8.                 listeTerrainLayers.Add(TerrainSpawn.refBiomes[i].terrainLayers[0]);
    9.             }
    10.         }
    11.         Terrain t = terrain.GetComponent<Terrain>();
    12.         t.terrainData.terrainLayers = listeTerrainLayers.ToArray();

    issue #2 : grass textures are missing


    the terrain details textures2D grass are not displayed either, but a green placeholder

    Code (CSharp):
    1. // same kind of code to init the grass
    2. List<DetailPrototype> listeHerbesTotaleNew= new List<DetailPrototype>();
    3. for (int i = 0 ; i < listeBiomesActifs.Length ; ++i)
    4. {
    5.     if (listeBiomesActifs[i])
    6.     {
    7.         for (int zz =0 ; zz < TerrainSpawn.refBiomes[i].listeHerbes.Count ; ++zz)
    8.         {
    9.             listeHerbesTotaleNew.Add( TerrainSpawn.refBiomes[i].listeHerbes[zz] );
    10.         }
    11.     }
    12. }
    13. DetailPrototype[] herbeProto = listeHerbesTotaleNew.ToArray();
    14. t.terrainData.detailPrototypes = herbeProto;

    a grass texture is something like this (in Resources)
    upload_2023-8-23_16-20-14.png


    # issue3 : TREE Lod / Billboard
    dont have the same behavior between play & build mode

    the TREES are rendered, but for some reasons, the LOD doesn't work the same at all.
    In PLAY MODE, Its seems like all my Trees are diplayed "speedTree-like". I see a lot of them, visiblity driven with the LOD system
    upload_2023-8-23_16-24-32.png

    but in BUILD mode, the billboard is used after a few meters only (cf screen).
    The trees are custom trees using Shader "Universal Render Pipeline/Nature/SpeedTree7 Billboard" .
    Maybe it must be added to compilation somewhere, but i dont know howto :(


    ---

    Nb1 : have 0 error log- like "cannot read texture" .
    Nb2 : everything is working fine in play mode, there is no "wrong texture path" mistake or a logical error like an empty "biome" or so.



    thanks for help; if anyone has an advice !
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    pink means that a shader was unable to render properly. Either the shader wasnt found, the material was not found, or a resource used by the material was not found etc

    You should probably state which exact version of unity and which exact URP package version etc you are on, or its tricky to know whats going on
     
  3. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    I have

    Unity version / Initialize engine version: 2022.1.0f1
    URP installed 13.1.8 (28 april 2022)

    started from an unity urp default project model, didnt add urp rendered later.


    upload_2023-8-23_20-13-41.png

    if i try to look at the "grass"

    Code (CSharp):
    1.     public static DetailPrototype LoadDetailsTexturePack(Object obj, float scale = 1.0f)
    2.     {
    3.         DetailPrototype aDetail = new DetailPrototype();
    4.  
    5.         float min = Random.Range(0.3f, 0.6f);
    6.      
    7.         float max = Random.Range(min, min * 2 * scale);
    8.  
    9.         aDetail.minWidth = min;
    10.         aDetail.maxWidth = max;
    11.         aDetail.minHeight = min;
    12.         aDetail.maxHeight = max;
    13.         aDetail.noiseSpread = 0.8f;
    14.         aDetail.noiseSeed= Random.Range(1500,10000);
    15.  
    16.         Color c1 = new Color(
    17.             Random.Range(0f, 1f),
    18.             Random.Range(0f, 1f),
    19.             Random.Range(0f, 1f)
    20.         );
    21.  
    22.         Color c2 = new Color(
    23.             Random.Range(0f, 1f),
    24.             Random.Range(0f, 1f),
    25.             Random.Range(0f, 1f)
    26.         );
    27.  
    28.  
    29.         aDetail.healthyColor = c1;
    30.         aDetail.dryColor = c2;
    31.         aDetail.prototype = (GameObject)null;
    32.         aDetail.prototypeTexture =(Texture2D)obj;
    33.  
    34.         Debug.Log("LoadDetailsTexturePack : " + obj.name);
    35.  
    36.         //aDetail.renderMode = DetailRenderMode.GrassBillboard;// !this.m_Billboard ? DetailRenderMode.Grass : DetailRenderMode.GrassBillboard;
    37.         aDetail.renderMode =DetailRenderMode.Grass;
    38.         aDetail.usePrototypeMesh = false;
    39.         return aDetail;
    40.     }
    41.  
    and some logs, they are succesfully loaded, i have the object.name in log.

    ------

    How can i progress to solve the problem and try to "debug" this ? I don't know where to look, or what to look for ?
     
    Last edited: Aug 23, 2023
  4. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    New : after more tests

    If i create a terrain inside editor, instead of "by script", all the above works and i have no pink elements.

    It means the terrain objects created by script are not correctly "shipped- built", or some initialisation are missing.


    Code (CSharp):
    1.  
    2.        // generated terrain code : like this, and are 100% ok in play mode
    3.        TerrainData terrainData = new TerrainData();  
    4.         terrainData.name = "terrainDataGenerated" + x + y ;
    5.         terrainData.size = new Vector3(terrainSize, terrainAltitudeMax, terrainSize);
    6.  
    7.         terrainData.baseMapResolution = baseTextureResolution;
    8.         terrainData.heightmapResolution = heightmapResolution;
    9.         terrainData.alphamapResolution = controlTextureResolution;
    10.         terrainData.SetDetailResolution(detailResolution, detailResolutionPerPatch);
    11.  
    12.  
    13.         List<TreePrototype> tlTrress = new List<TreePrototype>();
    14.         terrainData.treePrototypes = tlTrress.ToArray();
    15.  
    16.         List<DetailPrototype> tlDetails = new List<DetailPrototype>();
    17.         terrainData.detailPrototypes = tlDetails.ToArray();
    18.  
    19.         terrainData.wavingGrassAmount = 0.05f;    //Amount of waving grass in the terrain.
    20.         terrainData.wavingGrassSpeed= 0.05f;    //Speed of the waving grass.
    21.         terrainData.wavingGrassStrength= 0.05f;
    22.  
    23.  
    24.         terrain = Terrain.CreateTerrainGameObject(terrainData);
    25.         terrain.name = "terrainGenerated" + x + y + "-actif";
    26.         terrain.transform.SetParent(GameObject.Find("tuilesTerrains").transform);
    27.         terrain.transform.position = new Vector3(terrainSize * (x) , 0, terrainSize * (y));

    any clue how to fix this problem ? Else i ll change everything no more "CreateTerrainGameObject", but use a predefined list of manually created terrain game object inside editor..But i 'd prefer keep dynamique generation if possible

    Thanks !
     
  5. Armynator

    Armynator

    Joined:
    Feb 15, 2013
    Posts:
    59
    I'm pretty sure this is happeneing because you forget to set the material manually.
    Create a new terrain material with the URP terrain shader and apply it like this in your script:
    Code (CSharp):
    1. public Material myTerrainMaterial; //assign this in inspector
    2.  
    3. terrain.GetComponent<Terrain>().materialTemplate = myTerrainMaterial;
    (See Terrain.materialTemplate for reference)

    The problem behind this is that Unity still refers to the legacy builtin terrain shaders/materials when using Terrain.CreateTerrainGameObject.

    Also about this:
    It should have no effect in URP as you are referring to the legacy builtin shader. The shader you want is "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader" (called "Universal Render Pipeline/Terrain/Lit" in the editor)
    When creating the material in the editor and assigning it to the field in the inspector as described above, adding it to the always included list isn't necessary.
     
  6. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    Thanks a lot sir ! , there is progress terrains layers are now ok

    , but it didnt solve the terrainDetails and the trees behavior

    upload_2023-8-24_9-54-43.png

    any other "material" to change ?


    ----- EDIT

    Solved for LOD : it was Quality settings "perfomant," that has a lod bias of 0.4
    I still dont have textures for grass :(
     
    Last edited: Aug 24, 2023
  7. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    167
    if I'm not wrong TerrainDetails are not supported by URP, you may wanna use grass as trees.
     
  8. merfolkjh

    merfolkjh

    Joined:
    Sep 18, 2021
    Posts:
    20
    it's just a basic grass texture, compatible URP

    - Left side : the "dynamic terrain spawned"
    - Right side : the same object terrain but created in the editor, not "runtime created"
    - same code for both (heightmaps, trees, grass..)

    screenshot In "build" (in editor "play", everything is ok)
    upload_2023-8-26_21-51-49.png

    I still dig to solve this problem.

    If i believe the "frame debugger", on editor play, this seems to be the shader that draw the grass, how can i add thoses "hiddens" in the final build ? (or i am wrong and it's something else)

    upload_2023-8-26_21-58-15.png
    Thanks !

    #also the terrain layer are very diffferent, it looks "flat", in editor mode, it's not flat green. But it is an other problem. I ll search in the lighting & builds sections.
    https://forum.unity.com/threads/app...er-until-material-opened-in-inspector.815151/
     
    Last edited: Aug 26, 2023