I’m creating a game in which the player may select which grass it wants for his terrain. The grass was created with the terrain editor, using billboards.


To change the grass on runtime, I use this code:

public void SetGrassType(GameDataController.GameData.IEGrassType grassType)
{
    // do nothing if ground isn't defined
    if (m_Ground == null)
        return;

    // dispatch the grass type
    switch (grassType)
    {
        case GameDataController.GameData.IEGrassType.IE_GT_None:
            // hide the terrain details
            m_Ground.drawTreesAndFoliage = false;
            break;

        case GameDataController.GameData.IEGrassType.IE_GT_Soft:
            // show the terrain details
            m_Ground.drawTreesAndFoliage = true;

            // load the current grass billboard
            m_DetailPrototypes = m_Ground.terrainData.detailPrototypes;

            // change it
            if (m_DetailPrototypes[0].prototypeTexture != m_SmoothGrassBillboard)
                m_DetailPrototypes[0].prototypeTexture = m_SmoothGrassBillboard;

            // save the billboard changes
            m_Ground.terrainData.detailPrototypes = m_DetailPrototypes;
            break;

        case GameDataController.GameData.IEGrassType.IE_GT_Hard:
            // show the terrain details
            m_Ground.drawTreesAndFoliage = true;

            // load the current grass billboard
            m_DetailPrototypes = m_Ground.terrainData.detailPrototypes;

            // change it
            if (m_DetailPrototypes[0].prototypeTexture != m_HardGrassBillboard)
                m_DetailPrototypes[0].prototypeTexture = m_HardGrassBillboard;

            // save the billboard changes
            m_Ground.terrainData.detailPrototypes = m_DetailPrototypes;
            break;
    }

    // update the terrain details
    m_Ground.terrainData.RefreshPrototypes();
    m_Ground.Flush();
}

Where:

  • m_Ground is the Terrain object
  • m_SmoothGrassBillboard is a Texture2D containing the first grass texture
  • m_HardGrassBillboard is a Texture2D containing the second grass texture

When the above code is executed on the embedded Unity player, there is no problem: I can change the grass from an in-game option, and the change is effectively applied to my terrain. However, when I compile, install and run the project on an iPhone device, the details just disappear when I change the grass, only remains the terrain with his basic texture. Reverting to the previous option restores the details.


I verified if the objects (terrain, textures) were well assigned while I try to change the details, and I found no issue on this side. I also verified if my both textures were compatible with my device by swapping them, and there is no problem with that too.


Someone may explain to me what I’m doing wrong, and why I cannot change the terrain details on iPhone devices?

So I found the issue finally. I first noticed that it appeared on every built project, whether it is on Windows, iOS, or any platform which isn’t the editor. Then I tried to debug a built project using the deployed solution. The console logs said me what was the problem: the “Read/Write enabled” flag should be enabled for the both grass textures in order to allow the above code to work.