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 Propagant · May 05, 2017 at 02:20 PM · errorcrashdestroyhierarchyinstance

Unity crashes on destroying a massive amount of objects

Hi, I'm having a big problem with objects destroying. I've got a space game, you can fly with your space ship around the limited space and there is also a few enemies. All ships are modular, so they are built by the small parts (like lego). And if you hit some parts with your ship, they will be disconnected from the ship that you hit. 'Destroyed' parts have a "timer" that tells to the object when the object has to be destroyed. And there is a problem.. When a few objects are destroyed in one moment, it's okay. But when there is a massive amount of objects [for example 20] destroying in a same time, the game crashed and I have an error log, very popular - Access Violation 0xc0000005. So there must be something really bad and really wrong. Is there some 'memory limitation' or is there something with performance? Thanks for answer.

Comment
Add comment · Show 7
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 Deathdefy · May 05, 2017 at 04:34 PM 0
Share

If it becomes too heavy you can create a queue system for it. You could hide all your objects that you want to delete so they dont render and add them to the queue and just have them delete one after another ins$$anonymous$$d of all at once.

avatar image Cherno · May 05, 2017 at 08:25 PM 0
Share

20 objects doesn't seem like a "massive" amound. Anyway, try using a Coroutine to divide the destroying of the parts over several frames so there are less obejcts destroyed per single frame.

avatar image dashticle · May 05, 2017 at 09:33 PM 0
Share

The moderator queue must be quite backed up I guess... my answer is in limbo right now but I was going to suggest you implement a simple object pool to rule out too many Instantiate() or Destroy() calls causing performance related errors.

I haven't seen that specific error you mention but strange things happened in my programs with too many of those expensive calls causing lag. I fixed it by implementing object pooling. Good luck!

Ray Wenderlich guide to pooling

Unity Learn guide

avatar image ritoban · May 05, 2017 at 11:34 PM 0
Share

Are you using the latest version of Unity? Unity 5.3 had this problem (according to http://answers.unity3d.com/questions/950569/game-runs-in-editor-crashes-on-startup-after-build.html?childToView=951281#answer-951281)

You should also look at the stack overflow post here: https://gamedev.stackexchange.com/questions/110613/my-game-crashed-access-violation-0xc0000005

Lastly, if you haven't already fixed the problem, can you tell me how much memory you have in you're computer. If you're using an old system, you may have memory problems. This is such a low-level problem that I may not even be able to replicate it and will require you to investigate on your own. I am no authority in these subjects. Good luck!

avatar image RobAnthem · May 06, 2017 at 04:47 AM 0
Share

I've destroyed hundreds of objects at once, perhaps more is going on here? Are your objects running any code in OnDisable(), OnDestroy(), or ~ObjectsName()? Do any of these objects contain other objects that are from inaccessible DLL libraries?

Show more comments

3 Replies

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

Answer by Propagant · May 07, 2017 at 02:38 PM

Guys I have already solved my problem. There was a problem with mesh colliders. When you are destroying such a big amount of objects and each object contains its own mesh collider, it could crash. In my case, I was using mesh colliders with a quite complex mesh source. So that's it. Don't use mesh colliders in destroying a massive amount of objects. I think that's the answer ;P Thanks.

Pooling? There is nothing with pooling. As I said, I have modular ship that is built by the simple parts and every part has to be destroyed, not pooled. So pooling could be used in another case.

Comment
Add comment · Show 3 · 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 Recotech · Aug 28, 2017 at 07:03 PM 1
Share

You saved my day Propagant, I was stuck with this for 3 months.

avatar image JonPQ · Aug 28, 2017 at 07:11 PM 1
Share

Propagant is correct.. instantiate and destroy are very slow.... you will notice hitches and drops in framerate if you use them alot.... Its better to move them on and off screen, far from camera, and/or use object pooling if they can be re-used. If they cant be re-used... move them far from camera, and don't destroy until end of level.... if you must destroy... then add them to a list... and destroy them one per frame in a coRoutine... not all at once.

avatar image Propagant · Oct 30, 2017 at 12:30 PM 0
Share

Glad that helps guys...

avatar image
1

Answer by dashticle · May 09, 2017 at 05:20 AM

Hi,

You could try setting up a simple object pooling implementation to rule out some kind of errors by performance. Instantiate() and Destroy() are very heavy and should be avoided where possible, and the garbage collection in Unity is apparently not great so calling Destroy() a lot is especially bad.

While I haven't seen that specific error, my simulator behaves very strangely and throws errors when it tries to do too much in one frame. I got rid of this and alot of performance issues by embracing Object pooling. Check it out!

Guide by Ray Wenderlich

Official Unity Learn guide

Good Luck.

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
1

Answer by salamander555 · May 07, 2017 at 09:21 AM

Have you tried to build the game and then test it? to see if its just the limit memory of you unity or something else.

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

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

Destroyed Object Stops Scipt 1 Answer

Hierarchy not showing anything, getting KeyNotFoundException 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Build Iphone Issue 0 Answers

Unity Editor silently crashes straight away no error logs 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