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 /
This question was closed Oct 10, 2019 at 09:27 AM by xxmariofer for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by martygrof3708 · Oct 09, 2019 at 11:40 PM · scripting problemtriggeroptimizationlag

OnTriggerEnter causing lag spike?

My game runs fine until my player comes into contact with OnTriggerEnter. It adds a 6ms spike. And 380kb of garbage?

alt text

using UnityEngine;

public class PlayerHitBox : MonoBehaviour { public Player player; public bool isInTarget = false; public Tile tile; private TriggerObj trigger; private bool hittingGem = false;

 private void OnCollisionEnter (Collision collision)
 {
     tile = collision.collider.GetComponentInParent<Tile> ();

     if (tile != null && !tile.dead)
     {
         player.OnNewTile (tile);
     }
 }

 private void OnTriggerEnter (Collider other)
 {
     trigger = other.GetComponent<TriggerObj> ();

     if (trigger != null)
     {
         switch (trigger.type)
         {
             case Trigger.input:
             player.OnTargetTrigger (true);
             break;
             case Trigger.gem:
             if (!hittingGem)
                 player.OnHitGem ();
             break;
             case Trigger.wall:
             player.OnHitWall ();
             break;
             case Trigger.spike:
             player.OnHitSpike ();
             break;
             case Trigger.tornado:
             player.OnHitTornado ();
             break;
         }
     }
 }

 private void OnTriggerExit (Collider other)
 {
     trigger = other.GetComponent<TriggerObj> ();

     if (trigger != null)
     {
         switch (trigger.type)
         {
             case Trigger.input:
             player.OnTargetTrigger (false);
             break;
             case Trigger.gem:
             hittingGem = false;
             break;
         }
     }
 }

}

screenshot-1.png (213.6 kB)
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 WarmedxMints · Oct 10, 2019 at 01:28 AM 0
Share

on which case and method call is the spike and what do those methods in the player class do?

avatar image martygrof3708 WarmedxMints · Oct 10, 2019 at 04:57 AM 0
Share

I've fixed it. OnTriggerEnter was being called multiple times. I added in a boolean and its fixed.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Why do my first few collectable/powerup collisions cause lag but not later ones? 1 Answer

OnTriggerEnter() is occasionally not occurred 1 Answer

How can i detect by script when a character enter a hole in object ? 1 Answer

Void OnTriggerEnter not working 1 Answer

Why doesn't my NavMeshAgent go to a position on trigger? 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