Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SeaLeviathan · Mar 12, 2018 at 04:50 AM · optimizationgameobjectsgeometrytris

Large # of gameobjects run smoothly or alternative?

I have been working on a building game project in unity, a Lego sort, and one problem that I have recently come across is size. Small numbers of these bricks go together with little lag, but then the frames drop as the brick count increases: alt text

This image has about 1k bricks on the beautiful settings.

The bricks themselves have triggers on them that act as stud connections, and each brick has some script that handles connections and other such, all parented to an empty with a rigidbody (Set to isKinematic for now, so physics aren't playing a role in my frames). I would really like to know if there's a way to optimize this to allow for large scaling in the 10's of thousands of bricks, some trick about Unity's rendering/processing settings I don't know about, or maybe some mesh connection?

Any help would be appreciated, even if it the answer is find another engine

problembricks.png (433.9 kB)
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 ShadyProductions · Mar 12, 2018 at 05:13 AM 0
Share

Use a couple of big meshes to render the blocks.

avatar image hexagonius · Mar 12, 2018 at 03:06 PM 0
Share

maybe this helps you getting an idea of how you could approach this:

https://tomcc.github.io/2014/08/31/visibility-1.html

avatar image SeaLeviathan hexagonius · Mar 12, 2018 at 04:07 PM 0
Share

Yes thank you, that will definitely help for future if I can properly scale, to add even more optimization. The only problem I see with it is that if all of my bricks are visible at one time, the system is still processing all those tris. I got it down significantly by hiding the triggers, which I didn't realize were such a huge part, but still run into hiccups at about 5000 at once.

as of right now during testing, it looks like unity culls pretty well on its own, keeping tri counts low as long as they aren't actually visible, but the fact that they are still there may have a significant effect.

1 Reply

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

Answer by Harinezumi · Mar 12, 2018 at 03:26 PM

Summary from comments:
- low performance can be caused by various things, the usual cuplrits being rendering, physics, scripts, and networking
- to find out what causes the performance issues run the profiler (Window menu -> Profiler)
- in the profiler the percentage of a row is not that important, it's the Time column that tells you if something takes too long
- in this case it turned out Behaviour.Update() (scripts) take 4.99ms, which is relatively a lot. Optimising scripts helped. One way to optimise scripts is to try to offload logic that doesn't run every frame from Update() to coroutines
- to help with rendering many similar objects - as is the case with building blocks - batching (dynamic and static) and instancing (previously called geometry instancing) can help a lot (in this case it did). Batching can be turned on in the Player settings (Editor menu -> Project Settings -> Player), while geometry instancing can be turned on on individual materials (for those that support it, called "Enable GPU Instancing")
- don't bother with trying to manually discard sides of boxes that are not visible from your point of view, backface culling (run on the graphics card) automatically eliminates triangles whose normal faces away from the camera
- instantiating and destroying objects a lot can also cause poor performance, because they are costly operations, and allocate and deallocate memory that the GC needs to clean up. Instead, one can try using object pooling (there are various articles on the topic on the internet)
- to optimise physics, there are various rules. Firstly, NEVER directly modify transform.position of a game object that has a RigidBody on it, it is the most time consuming. Instead use Rigidbody.position, or even better Rigidbody.MovePosition(). Second, always apply changes to physics in FixedUpdate() (or functions called from FixedUpdate()), not from Update() or LateUpdate()
- another physics optimisation is to approximate the collider of complex shapes with something simpler: either make the MeshCollider convex, or - if possible - use multiple primitive colliders, like Sphere- and BoxColliders

Original comment:
The issue can be graphics, physics, or the scripts. Run the profiler and check what takes so much time. In my experience 1k objects shouldn't bring the Editor to a halt, except if they have really complicated meshes or scripts on them.
My hunch is that the issue is caused by physics, the objects continuing to collide after they get connected. Note that even if you set a rigidbody to kinematic, even though it will not move, it does take part in collisions (as far as I know).

Comment
Add comment · Show 8 · 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 SeaLeviathan · Mar 12, 2018 at 04:42 PM 0
Share

alt text

Looks like physics isn't a biggie, but behaviour update is? Does this mean that if I get rid of unnecessary update functions it will actually make it run that much better?

Taking the rigidbody off of the parent object gave me like 10fps back, pretty nice, so the idea of only giving it a rigidbody when needed is definitely on the list.

last note, in your opinion, would going as far as to make a cube object with six individual sides, and only render the sides on say the front half that you face, be a worthwhile optimization or just cause more problems and processing in the long run?

profiler.png (344.1 kB)
avatar image Harinezumi SeaLeviathan · Mar 12, 2018 at 05:05 PM 1
Share

Based on the profiling rendering is the biggest issue. You could try turning on dynamic batching in player settings, as well as geometry instancing in the renderer/material of your objects (if I understand it correctly, you are rendering a lot of the same geometry, exactly what geometry instancing is used)
The percentage something takes is actually not that important, it's the time that matters. 4.99 ms in Behaviour.Update is quite a lot, so optimizing your scripts, trying to only run when needed (e.g. NOT using $$anonymous$$onoBehaviour.Update()) should probably improve how well it runs.
I would not care about marking sides of the boxes to be rendered or not, backface culling handles that for you (if the normal of a triangle faces away, the triangle is not even sent through the vertex shader)

avatar image SeaLeviathan Harinezumi · Mar 12, 2018 at 06:48 PM 0
Share

Ah thanks again! Unless im missing something, dynamic batching was already turned on. Instancing is amazing and gives me at least 20fps after applying a material with it enabled. after running another test I was able to save 3 ms on update by getting rid of some pretty useless update functions. The only ones I can't get rid of are character input, is there somewhere better to put things like keydown and mousemovement than update?

Show more comments
avatar image TreyH SeaLeviathan · Mar 12, 2018 at 08:18 PM 1
Share

Unity is typically pretty good about large numbers of objects, but anything you tell Unity to do in a Behaviour will be done for each object you have out there. Can you expand the profiler to see which specific script / function call is being most problematic and post that here?

avatar image SeaLeviathan TreyH · Mar 13, 2018 at 03:43 AM 0
Share

thanks for the response, but as I said in the post above I was able to get rid of the lagging due to the update, sorry :/ but thanks for asking!

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

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

Loading many gameObjects 1 Answer

How to reduce polygon count? I have meshes from pointclouds. 0 Answers

How to optimize usage of many GameObjects? 2 Answers

Don't update gameObjects too away from player. 1 Answer

Optimize Having Thousands of GameObjects 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