Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 29, 2015 at 12:49 AM by getyour411 for the following reason:

Other

avatar image
0
Question by max1s · Dec 30, 2013 at 12:56 AM · terraintreegenerationtrees

Stuck on how to get trees to show after calling CreateTerrainGameObject()

Hi,

I am trying to generate some trees for my terrain but with no luck. NOTE: when I inspect the treeInstances[] array I have the correct number of trees within the array but nothing appears on my screen. The problem is that this is incredibly hard to debug since the objects dont appear within the hierarchy.

Anyway I have a Main.cs

 terrain = Terrain.CreateTerrainGameObject(TerrainGeneration.GenerateTerrain());

then I have a terrainGeneration class which holds these two relevant methods:

     public static TreePrototype[] BindTreeToBrush()
     {
         TreePrototype[] trees = new TreePrototype[1];
         trees[0] = new TreePrototype();
         trees[0].prefab = Resources.Load("ScotsPineTypeA") as GameObject;
         return trees;
 
     }
     public static TreeInstance[] TreeMaking(TerrainData myTerrain)
     {
         List<Vector3> treeLocations = TreePositioning(400, 3);
         List<TreeInstance> trees = new List<TreeInstance>();
         for(int i = 0; i < treeLocations.Count; i++ )
         {
             TreeInstance tree = new TreeInstance();
             tree.prototypeIndex = 0;
             Vector3 actualPosition =  treeLocations[i];//Helper.TerrainToWorldPosition(myTerrain, 512, treeLocations[i]);
             actualPosition.y = heights[(int)actualPosition.x, (int)actualPosition.z];
             tree.position = actualPosition;
             trees.Add(tree);
         }
         return trees.ToArray();
 
     }
 These two methods are being called inside the class before the GameObject is returned to main.

If I haven't given enough information please comment and I will supply more. Note I know I dont need to pass the TerrainData to the function but that doesnt matter.

Ow also the bind tree to brush function works because I can view that tree in the editor when I click the tree tab.

UPDATE: If I change tree.heightscale and tree.widthscale = 1 then I can get them to appear at the corner of the map in black. But they are not coloured nor are they in the correct positions even though when I print the Vec3 for position held in memory it gives me a location upon the terrain.

alt text

Thank you

best.jpg (271.1 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image max1s · Dec 30, 2013 at 01:21 AM 0
Share

Ow also if anyone has any tutorials on programatically adding trees using the Terrain class or any sample working code I would really appreciate it because the internet seems pretty dry for that kind of thing..

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my Tree on Terrain not look like the Original Prefab it was made of? 0 Answers

Cannot place trees on terrain 0 Answers

Tree billboards clipping into terrain 1 Answer

Tree Creator Problems 1 Answer

Can't use tree brush tool 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges