• 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 /
avatar image
2
Question by The-Oddler · Jan 22, 2012 at 01:11 PM · terraintree

Terrain: Placing trees from code, but they are black...

Hi,

I'm adding trees to my terrain from code (at random positions), and they show up, though they are completely black... When I place the same tree-prefab from the editor, they do have color...

In code I first create the terrainData and then create the terrain using Terrain.CreateTerrainGameObject(terrData);. Also tried first adding the treePrototypes to the terrainData, then creating the terrain, and then adding the trees directly to the terrain. I also flush the terrain after this (just to be sure, didn't seem to help anything.)

Someone asked to clarify: What I do is I create a terrainData, to this terrainData's treePrototypes I add all the tree-prefabs (and set their bendfactor), then I place a few trees on the terrain at a random position by adding TreeInstances to terrainData.treeInstances. This gives my a terrain, with a bunch of black trees... (This all happens when the game is running.) Then when I go to the scene view, select the created terrain, and then add TreeInstances using the painting-thing, I get properly coloured trees! Though while writing this, I realize that I probably just forgot to set the color value in the TreeInstance when making them in code. I will check this when I get home (end of the week.)

Anyone any idea why this is?

Thanks!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by The-Oddler · Aug 06, 2012 at 07:55 PM

I forgot to post the fix I found, so let's do that now.

Apparently you have to set a colour value for the trees, and by default this is black. If you set this to white, the normal texture colour of the trees will be shown.

Comment
Add comment · Share
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
0

Answer by Jaap Kreijkamp · Jan 23, 2012 at 01:22 AM

From you question it's not clear if you tried the tree by placing it by putting prefab on terrain or by terrain place trees brush. It looks like the shader used by the tree is not a terrain tree shader. Does the tree turn out black if you use the place tree brush or does it turn out correct then? The shaders used by the tree must be from the Nature group. The tree should be one mesh (with possibly different submeshes for the different materials). As your terrain instance is also created dynamically you could try if trees come out by placing them with brush while game is running in editor.

Comment
Add comment · Show 1 · Share
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 The-Oddler · Jan 23, 2012 at 03:32 PM 0
Share

I added more info, and also probably the fix :P Thanks for asking this, it made me retrace my steps once again, and by doing so I think I found the problem :D Though can't test right now, will report later ;)

Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain tools with personal model 1 Answer

Placed Trees in Terrain are white planes? 1 Answer

How to make toon shader work with terrain place trees? 1 Answer

Cannot draw tree from blender to terrain in unity, Why? 2 Answers

Adding custom trees in UnityTerrain. 1 Answer


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