Search Unity

Unity 4 Terrain Settings "Tree Detail Objects"

Discussion in 'Editor & General Support' started by EdLan, Mar 6, 2013.

  1. EdLan

    EdLan

    Joined:
    Jan 18, 2013
    Posts:
    4
    Dear Forum

    In Unity 4 there is a new Terrain setting checkbox in the "Tree Detail Objects" section called "Draw".

    Is there a way to access this setting trough scripting at runtime? I didn't found any documentation for that new setting. And I also tried to find something trough code completion in Mono Develop. But until now I didn't found anything.

    Cheers, EdLan
     
  2. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    Did you find a solution to this one?
     
  3. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
    I need this too.
     
  4. Ben-Massey

    Ben-Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    I had no luck finding any supporting documentation, however you could manually set your detail density to 0 for your foliage.
     
  5. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
    I am not sure is the same and make the difference, I use these to reset options there:

    terrain.treeBillboardDistance = 5;
    terrain.treeDistance = 0;
    terrain.basemapDistance = 0;
    terrain.treeMaximumFullLODCount = 0;
    terrain.detailObjectDistance = 0;
    terrain.detailObjectDensity = 0.0F;
    terrain.treeCrossFadeLength = 0.0F;
     
  6. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Posts:
    113
    +1, I would also like to see this property exposed through script. Modifying 'detailObjectDensity' does work, however it's incredibly slow at runtime.

    Would be great to have a 'detailObjectDraw' boolean.
     
    Last edited: Aug 1, 2014
  7. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The problem is that the variable is private (m_DrawTreesAndFoliage) but if you like you can use reflections to get / set it.
     
  8. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Posts:
    113
    Ah right, that does work, however it doesn't seem to refresh in-game unless I have the Terrain GameObject selected in the inspector with the 'Draw' check box visible. Do you know why this is, or if there's a way to emulate the behavior through script at run time?

    Calling Terrain.Flush() doesn't seem to work either (even if it did, it causes a large frame spike). The main reason I'm trying to toggle this flag in the first place is for performance reasons. I know I'm probably trying to do something non-standard with Unity's terrain by creating a smooth transition from detail to no-detail, but if I could just get the behavior of toggling that check box in the editor to happen at run time, I think it would do it for me without a hitch.

    Code (csharp):
    1. FieldInfo fi = myTerrain.GetType().GetField("m_DrawTreesAndFoliage", BindingFlags.NonPublic | BindingFlags.Instance);
    2. if (fi != null)
    3.     fi.SetValue(myTerrain, value);
     
    Last edited: Aug 1, 2014