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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

terrain trees random rotation doesn't work

Discussion in 'Editor & General Support' started by ghiboz, Jun 10, 2015.

  1. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi all!
    I've noticed that using the terrain and the trees placement with the random tree rotation the trees are placed all with no rotation...
    the strange thing is that I do this script:
    Code (CSharp):
    1. GameObject go = Selection.activeGameObject;
    2. var terrain = go.GetComponent<Terrain>();
    3. for (int i = 0; i < terrain.terrainData.treeInstances.Length; i++)
    4. {
    5.     Debug.Log("Rotation: "  + terrain.terrainData.treeInstances[i].rotation.ToString());  
    6.     terrain.terrainData.treeInstances[i].rotation = 0.0f;
    7.     Debug.Log("New Rotation: "  + terrain.terrainData.treeInstances[i].rotation.ToString());
    8. }
    the log tell me that the rotation is effectively randomized, but the 3d is still not rotated..
    the line where is set the rotation to zero doesn't work

    thanks!
     
  2. bob_the_pr_bot

    bob_the_pr_bot

    Joined:
    Aug 5, 2016
    Posts:
    15
    I'm having a similar issue - I'm creating a terrain in c# scripts and adding trees to it, and setting TreeInstance.rotation to random values, but all the trees are drawn with the same rotation. The documentation says it's in radians, I thought maybe there was a mistake and tried degrees but that doesn't help.

    Does this happen to everyone else? Any idea how to fix it? Is it a bug in Unity? Should I report it?
     
  3. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    seems that works only with speedtree trees, noway for custom trees
     
  4. bob_the_pr_bot

    bob_the_pr_bot

    Joined:
    Aug 5, 2016
    Posts:
    15
    Yeah I figured it out in the end. Really frustrating as it makes the Unity custom tree creator basically useless.