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 sammy252 · Dec 14, 2017 at 09:48 AM · collider2d2d collision2d physics

Lag Caused by Overlapping 2D Colliders

I don't know whether this is a problem but from the articles i have seen elsewhere and all the solutions i have tried this seems to be the only source of the problem.. Iam making a 2D shooting game in which enemies are coming to attacks player from left and right side.. At first i was instantiating enemies and bullets and destroying them by comparing tags..

For example this script was on my bullet

public class

{

public void OnTriggerEnter2D(Collider2D col)

{

     if (col.CompareTag("enemy1"))
     {
         Destroy(this.gameObject);
     }

     if (col.CompareTag("enemy2"))
     {
         Destroy(this.gameObject);
     }
     
 }

}

however the lag caused was insane and i read that instantiating and destroying objects multiple times can cause that.. i then reverted to POOLING and placed all my prefabs in the script using POOLING method.. still it wasn't to great effect.. the only source to my problem which i can deduce from this is that multiple 2D polygon colliders overlapping each other are causing this lag.. i have tried attaching rigidbody 2D and AreaEffector 2D with it and making my rigidBody Kinematic but to no avail.. If there are even 20,30 enemies in my scene but there are not colliding with each other the game runs smoothly. But if there are only 5,6 but their colliders overlap then they cause insane lag.. Any person who have experienced a problem like this before or who can provide an alternate, this would be a massive help for me..

Also since iam using only two enemies and making multiple copies of them the tags are also being reused which i have assigned to them which are "enemy1" and "enemy2" respectively. Does this also cause problem since unity may be unable to track the proper tag if 10,12 enemies are using the same tag ??

Comment
Add comment
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

1 Reply

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

Answer by Ali_Dev3D · Dec 14, 2017 at 12:31 PM

If you are putting colliders on the whole body of the enemies then they are bound to overlap each other.. since your game is a 2D one i think what is happening is that when 2 or more enemies are overlapping each other their colliders are overlapping and this is causing the lag.. what i would suggest is remove the complete collider and only place it on the particular area where you want to hit the bullet..

also please ensure that the pooling algorithm which you are using is being called at correct time.. hopefully this would solve your problem.

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

74 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

Related Questions

Create colliders placed over polygon's perimeter 1 Answer

2d Object Increases in Speed with Each Collision 0 Answers

Why Does Object Keep Getting Faster? 1 Answer

2 collisions/colliders not working properly (gap between the 2 objects that collide) 0 Answers

2D pixel collision & destruction 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