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 Kourosh · Apr 08, 2011 at 07:41 PM · instantiateperformancedrawcallsoptimizepolygon-count

Mass object instantiation issue.

Imagine you have a mesh of only 5 or 6 polygons, and you need to instantiate a whole bunch of them. maybe 100. It's like you press hold the mouse button and will instantiate using a timer. every 0.05 sec. So I noticed that the performance falls dramatically( Draw call arises rapidly) . I'm kinda surprised here since unity is able to handle way more polygons, on each frame. So my guess is that objects that are instantiated on runtime are dealt with differently than ones already there before the level starts. i need to add that after instantiation they are static objects. So what's the best solution out there?

Edit: these small objects are sharing the same material however on the moment they are instantiated i give them a random color.

Cheers,

Comment
Add comment · Show 3
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 AngryOldMan · Apr 08, 2011 at 07:57 PM 0
Share

What do the objects contain? (ie,rigidbodies, colliders etc) chances are the performance falls due to the fact you are instantiating so many objects, once it's caught up with itself and stopped instantiating how does it run?

avatar image Kourosh · Apr 08, 2011 at 08:28 PM 0
Share

Oops, I forgot, no rigidbody/collider is attached.

avatar image Kourosh · Apr 08, 2011 at 08:33 PM 0
Share

it's still slow even when stopped. I check it with profiler.

2 Replies

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

Answer by Eric5h5 · Apr 08, 2011 at 08:48 PM

I'd recommend using the Mesh class to construct a single mesh made from the polygons, rather than having a separate object for each one.

Comment
Add comment · Show 7 · 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 Kourosh · Apr 08, 2011 at 08:56 PM 0
Share

you mean after the mouse is up, i combine them into a single mesh? sounds good, however if we want to remove few of those object, then we can't.

avatar image Eric5h5 · Apr 08, 2011 at 09:00 PM 0
Share

No, I mean construct the mesh continuously as the mouse is held down by adding polygons as necessary. You can remove some of the objects by rebuilding the mesh $$anonymous$$us the appropriate polygons.

avatar image Statement · Apr 16, 2011 at 04:29 PM 0
Share

Yeah, you'll probably get sky high draw call count with separate objects. $$anonymous$$aking a mesh out of it would reduce the draw calls significantly (to 1, from 100s). A down side is that you can't put individual scripts on these objects any longer, so you have to rethink any possible behaviour these individual objects would have had. But it's doable, and you'll combat the frame drop. +1

avatar image Kourosh · Apr 16, 2011 at 04:31 PM 0
Share

There reason I can't really combine these objects is that, users need to be able to remove any number of these objects at any point in time.

avatar image Eric5h5 · Apr 16, 2011 at 06:21 PM 1
Share

@$$anonymous$$ourosh: you can still combine them, it's just a little more complicated. See here for something related: http://forum.unity3d.com/threads/4477-in-and-out-of-a-combined-mesh

Show more comments
avatar image
3

Answer by PrimeDerektive · Apr 08, 2011 at 08:03 PM

try rolling your own recycling system.

Decide what you think the maximum amount of objects of that type you think will ever have at any one time will be, and instantiate (and disable) that many and add them into an array in Start().

Then, whenever you need one, iterate the array, enable the next object in the array, place it wherever you want it "instantiated" so forth, then when you're done, disable it again.

See this answer for more info.

Comment
Add comment · Show 2 · 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 Kourosh · Apr 08, 2011 at 08:31 PM 0
Share

What if i put those objects somewhere in the scene, around 100 of them. So that they are there from the beginning of the level. Just relocate them when mouse clicked? I mean would static feature (the checkbox that renders all static objects) work here?

avatar image Statement · Apr 16, 2011 at 04:28 PM 0
Share

No, since you move them they aren't static.

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

No one has followed this question yet.

Related Questions

Excessive VBOs and no batching while instantiating prefabs 0 Answers

Instantiate vs caching GameObject in scene 3 Answers

Is there anyway to get Unity GUI to cache an image? 1 Answer

Beast lightmapping and draw calls 1 Answer

Can an animated object become static again? 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