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 ExtremePowers · Oct 19, 2014 at 07:30 PM · instantiatemeshlaggrassbillboard

Efficient mesh instantiation

Is there a effecient way to place 10000 meshes on a terrain, without making the game lag. This is because I want to make a terrain with grass on it, so I would need to instantiate around 10000 meshes for a decent look. Note: The terrain is a mesh and is generated at run-time so I can't use the built-in tools..

Comment
Add comment · Show 12
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 Wisearn · Oct 20, 2014 at 09:53 AM 0
Share

You can place them out over the span of several frames ins$$anonymous$$d of trying to create them all in the same frame.

For example, with a coroutine you can use a while loop with a yield return null; inside it so it will skip a frame for each iteration

This way you could instantiate maybe a couple of hundred to a thousand per frame ins$$anonymous$$d of waiting for everything.

avatar image ExtremePowers · Oct 21, 2014 at 01:53 PM 0
Share

I have a problem, my yield return null line says that it needs a semicolon which it has.

 function Grass() {
     var chunkGrass = 0;
     while (chunkGrass < grassPerChunk) {
             chunkGrass++;
             if (chunkGrass == grassPerChunk / 20) {
                 yield return null; //UCE0001: ';' expected. Insert a semicolon at the end.
             }
     }
 }
avatar image HarshadK · Oct 21, 2014 at 01:57 PM 0
Share

In JS you do not need to specify 'yield return null', It is used in C#. In JS just use:

 yield;
avatar image _dns_ · Oct 21, 2014 at 03:05 PM 1
Share

Hi, I don't know exactly what are your needs but 10k meshes or objects is a lot to manage for an engine. Why don't you create 1 mesh composed of 10k quads, each representing 1 grass leaf ?

avatar image ExtremePowers · Oct 21, 2014 at 04:07 PM 0
Share

@Harshad$$anonymous$$ Thx :)

@dns How would I do that? :)

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by iwHiteRabbiT · Oct 21, 2014 at 04:28 PM

Have already made a scatter tool which did what you want. Bad idea ^^'. Instancing a lot of gameObject slow down considerately the framerate.

However, if you can't create a "single" mesh for your all grass, you could try to manage yourself by saving each mesh transformation matrix in a single array. After, in Update() for exemple, drawing yourself via DrawMesh (async drawing with full rendering pipeline) or DrawMeshNow (sync drawing without unity rendering pipeline).

With this, you never instanciate anything, just yield the creation of all the matrix.

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 Little_Turtle · Feb 01, 2017 at 09:05 AM

A better answer is to group grass in the same mesh. This way you create one mesh spawning many grass instances (like a sector) in a single object. Each grass might consist just of two triangles but you are free to create as many triangles as far away from each other as needed.

If you putting you combine your different grass textures in a clever way you can even put many different grass and flower combinations closely (or with some space in between) together so you can use a single pair of triangles to draw two or more grass groups together (if you use real 3d to draw the grass).

Also remember creating 10000 times a mesh is expensive, creating 10000*2 triangles within a mesh is cheap but also creating 10000 times an object is expensive but having 10000 existing objects being moved as necessary (grass that is not visible any more gets reused by just moving it to a new location).

This way you can have almost instant appearing grass without the costs of creating too many objects.

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

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

31 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 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

Grass on mesh 0 Answers

Creating more objects with code. 2 Answers

How to create billboarding planes 6 Answers

Instantiating a gameobject causes a lagspike 2 Answers

how can I instantiate an object specifically at the intersection of a collider and a mesh 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