Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get Trigger collider info cost strange high performance

Discussion in 'Physics' started by FeynmanRen100, Jul 4, 2015.

  1. FeynmanRen100

    FeynmanRen100

    Joined:
    Sep 6, 2013
    Posts:
    22
    Hi there,
    I have a rigibody collide with 2d triangle , the code is like this:
    Code (CSharp):
    1. public class InstalKill : MonoBehaviour {
    2.     public void OnTriggerEnter2D(Collider2D other)
    3.     {
    4.         if(other != null)
    5.         {
    6.             //var player = other.gameObject.GetComponent<Player>();
    7.             //if(other.gameObject.tag == "Player")
    8.             //if(player != null)
    9.             if(other.name.StartsWith("Player"))          
    10.             {
    11.                 LevelManager.Instance.KillPlayer();
    12.             }
    13.         }
    14.     }
    15. }
    the profiler say this function cost really high cpu , but I can't figure out what's affects ?
    the profiler image is attached blow.

    Any advise will be appreciated.

    thanks
     

    Attached Files:

  2. Damasch

    Damasch

    Joined:
    Aug 28, 2014
    Posts:
    4
    Code (CSharp):
    1. other.name.StartsWith("Player")
    could be the performance killer. But nearly 1.4 seconds definitely seems to be too much for it.

    Did you try out the commented line
    Code (CSharp):
    1. //if(other.gameObject.tag == "Player")
    before? Did it work better?
    Did you try it out without any if-statement yet?