• 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 /
This question was closed Jul 26, 2017 at 07:34 PM by Spiritfall for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Spiritfall · Jul 25, 2017 at 10:18 PM · collisionrigidbody2dontriggerenterfreezephysics 2d

OnTriggerEnter2D first collision causes lag/freeze

Hey all, I'm currently developing a mobile game and I ran into a small problem. When my player first collides with an enemy, the game freezes for a bit.

The weird thing is that this happens only when first time OnTriggerenter2D is called. Enemies that collide with my player afterwards do not cause any lag. I profiled the game and it shows that three things cause this issue, specifically: Physics2D.CompileContactCallbacks, Physics2D.SendContactcallbacks and Physics2D.SendTriggerContactCallbacks.

My player has a dynamic rigidbody2D attached as well as BoxCollider2D that has set OnTrigger to true. The same applies to the enemies, except the rigidbody2D is set to kinematic.

Here's a screenshot from the profiler: https://i.imgur.com/RDVHeXg.png

I'm testing it on Samsung S4 mini.

Any ideas how to fix this?

Thanks!

Comment
Add comment · Show 2
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 FlaSh-G · Jul 26, 2017 at 08:38 AM 1
Share

The time a line takes is its total time, including their children lines. This means that CompileContactCallbacks itself doesn't take long, it takes long because SendContactcallbacks takes long. And this in turn takes long because... you get the point.

So what's really slowing your code down is Enemy.OnTriggerEnter2D, and that is your code. Without posting this method, it's hard to help you any further.

avatar image Spiritfall FlaSh-G · Jul 26, 2017 at 07:32 PM 0
Share

Yeah I totally missed that Enemy.OnTriggerEnter2D was causing this, I was super tired when I posted this. After getting some sleep I noticed that Enemy.OnTriggerEnter2D was using File.Open (System.IO) that caused the freeze.

Thank you for your time helping me solve this issue!

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Spiritfall · Jul 26, 2017 at 07:34 PM

Duh, I didn't notice that OnTriggerEnter2D was using File.Open (System.IO) that was causing the freeze. Everything runs smoothly after removing it from OnTriggerEnter2D.

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

104 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

IsTrigger Effecting collision 1 Answer

Unable to get OnTriggerEnter to work.[JS] 2 Answers

How to only delete one of two collided objects? 1 Answer

OnTriggerEnter Bad Performance - Bad Code? 1 Answer

Child calling parent's OnTriggerEnter when no Rigidbody is attached to child 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