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 /
avatar image
0
Question by SuIXo3 · Dec 11, 2012 at 06:01 PM · instantiateterraincrashtree

Instantiate 697283 trees by script? Crash!

I'm trying to instantiate 1 tree (prefab) per red pixel of the second splat map (forest ground texture). The code works, as I tried some small lines to count the pixels that would allow the instance of the tree. The total count is 697283 pixels. That would mean at least that number of trees and more as for each square unit there should be like 10 trees for the forests to look nice(but that isn't coded yet). The splats are 2048x and the terrain size is 8192 units (squared).

The problem is unity crashes when I hit start (not so much crash as just stay there doing nothing, I just close it with the task manager). Is there a limit of allowed prefabs in the scene? Or is it just the computer dying because there's too much stuff?

Does anyone knows a nice solution?, other than painting them by hand (which is my last resort[the map is huge])

NOTE: the trees are a couple of planes put in cross with a texture, so they are really low poly. I even tried with untextured cubes to see if the crash was because of the trees but it still did. And btw, the mass placement of trees from the terrain tab doesn't help me as you can't choose the terrain type.

Comment
Add comment · Show 9
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 Eeppi · Dec 11, 2012 at 06:11 PM 1
Share

What happens if you complile your scene and open exe? Does it crash?

avatar image SuIXo3 · Dec 11, 2012 at 06:21 PM 0
Share

nice idea! I tried, and it works! But it lags horribly. So I think it's an optimization problem. $$anonymous$$aybe I should script a drawing distance, applied directly to the tree prefab and based on main camera distance. Also the game crashes when I go back with the cam to see the whole terrain at once.

But the views are amazing :))

Thanks for the tip! I just hope the optimization script will allow me to enter the test play in unity.

avatar image SuIXo3 · Dec 11, 2012 at 06:48 PM 0
Share

I tried to limit the draw distance to a 100 units from the camera but it crashed. And this time it crashed good, gives me a memory allocation error. With the build it doesn't even show any tree, yet it still lags.

avatar image DaveA · Dec 11, 2012 at 07:59 PM 0
Share

What are you actually trying to accomplish, and why wouldn't the usual method of terrain-based trees work for you?

avatar image SuIXo3 · Dec 11, 2012 at 08:18 PM 0
Share

Usual method of terrain-based trees? Do you mean the "$$anonymous$$ass Place trees" in the "Terrain" tab? If so it is no use to me because you can't choose to place them only on certain terrains. In my case, the trees should be placed only where there is forest ground, which is in the second splat map, as red. So ins$$anonymous$$d of painting by hand, because the terrain is complex, (there are many small patches of forest ground ), I want to do it automatically. The trees have no real gameplay use, it's just decorative. But they must be there or it would look weird.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eric5h5 · Dec 11, 2012 at 09:05 PM

You can't have anywhere near that many separate objects. Generally you should not have more than a few thousand, and fewer is preferable if possible. What you should do is use the terrain system, which is already optimized to handle large amounts of trees properly (it doesn't use separate objects for them). You have complete control over how you place trees by script; look up the TerrainData class in the docs. Otherwise you'd have to make your own tree system using the Mesh class.

Comment
Add comment · Show 5 · 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 SuIXo3 · Dec 12, 2012 at 01:09 AM 0
Share

Yes but you can't place trees with the terraindata. I'd have to use the brush, but it's a tedious process. And not efficient if I want more maps.

avatar image Bunny83 · Dec 12, 2012 at 01:21 AM 0
Share

@SuIXo3:
Brush? I thought you talk about ingame creation?
http://docs.unity3d.com/Documentation/ScriptReference/TerrainData-treeInstances.html

Not efficient? I agree that the terrain engine is far from being perfect, but i guess it's like 100 times more efficient than what you've tried above ;)

avatar image SuIXo3 · Dec 12, 2012 at 12:16 PM 0
Share

I know it is efficient, the first thing I did with my tree model was to test it painting it with the brush, and it looks nice. But the .treeinstances...isn't it only to get the number of trees? How is it usable to place them at certain coordinates?

avatar image Eric5h5 · Dec 12, 2012 at 05:53 PM 1
Share

No, that wouldn't be very useful. Please read the docs for TerrainData.treeInstances and the TreeInstance struct.

avatar image SuIXo3 · Dec 12, 2012 at 07:57 PM 0
Share

I just found Terrain.AddTreeInstance. I guess I could use that. I'll try tomorrow. Thanks!

avatar image
0

Answer by jRocket · Dec 11, 2012 at 09:08 PM

Make sure that they are set to static so Unity is batching them into a one draw call(Pro only). If that doesn't help or work, try making clusters of trees as one object and reduce the amount of tree objects actually being generated. If that doesn't work, you may have to make some kind of cell/grid based loading system, where only the trees in the nearest cell are loaded into memory at any one time.

Comment
Add comment · Show 4 · 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 SuIXo3 · Dec 12, 2012 at 01:05 AM 0
Share

I was thinking to do something like that. I guess I would have to code the generation of trees in the Update function, then within the pixels loop, set a conditional based on number of tree and some more stuff. I'll see if I think of something.

avatar image Bunny83 · Dec 12, 2012 at 01:17 AM 0
Share

Have you read the DrawCallBatching page? The last paragraph at the very bottom describe an example with trees...

Like Eric said, seperate objects have quite an overhead (Gameobject, Transform, Renderer, $$anonymous$$esh). When Unity batches object it creates an additional combined version. Such a setup can't be handled by any game engine out there 500k objects and i guess each one has at least 100 tris? Event the triangle count would be crazy without some sort of LOD system.

avatar image SuIXo3 · Dec 12, 2012 at 12:27 PM 0
Share

looks nice but I don't have Pro. I wish I had, but 1500$ is too much for the moment :(, maybe one day :).

And no, the trees have 4 tris, 2 quads. They are just a couple of planes with texture. They will look small, as it's just decorative and has no impact on gameplay(it's a strategy game like...total war in the campaign map). I thought of a LOD system, but it's a pain to do. It there one in unity or do I have to do it myself? By changing the meshes based on distance and all I guess. Or maybe there is some script out there from which I can get ideas?

avatar image Eric5h5 · Dec 12, 2012 at 05:57 PM 0
Share

That still won't work with so many trees anyway. They really really should not use separate instances for each one.

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Convert Terrain trees in to real trees 1 Answer

Terrain addTreeInstance crash 1 Answer

How do I instantiate the TerrainToolKit script? 1 Answer

Plant grass or tree with an image 0 Answers

Why does my water display itself above my trees? 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