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

OnTriggerEnter2D behaving like OnTriggerStay2D.

Discussion in 'Editor & General Support' started by xCyborg, Nov 15, 2013.

  1. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    632
    A Rigidbody2D with a collider hits a trigger BoxCollider2D, I implemented only OnTriggerEnter2D, it gets called but almost every frame as in OnTriggerStay, I switched to OnCollisionEnter2D and made the required adjustments and ir works fine, firing only once until the rigidbody back off and hit again.
    Is there something wrong with OnTriggerEnter2D?
     
    blox5000 likes this.
  2. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    632
    ?
     
    blox5000 likes this.
  3. LemonLime

    LemonLime

    Joined:
    Nov 16, 2013
    Posts:
    3
    I'm encountering the same problem. I put a Debug.Log inside the function, and it continually fires as the player is inside the trigger.
     
    blox5000 likes this.
  4. LemonLime

    LemonLime

    Joined:
    Nov 16, 2013
    Posts:
    3
    I figured out why this is happening. When an object is in motion (including rotation in my case), it continues to fire the OnTriggerEnter2D method since the transform is continually changing. At least that was the issue for me.
     
    blox5000 likes this.
  5. izzycoding

    izzycoding

    Joined:
    Apr 22, 2013
    Posts:
    3
    I was experiencing this too. however I have used a List<GameObject> to hold a list of all the trigger objects and only add them if they are not already in the list.
     
    blox5000 likes this.
  6. eknsmr17

    eknsmr17

    Joined:
    Oct 22, 2013
    Posts:
    1
    void OnTriggerEnter2D(Collider2D col)
    {

    if (col.gameObject.tag == "logo")
    {
    theScore += 10;
    textfieldScore.text = theScore.ToString();

    Destroy(col.gameObject.collider2D);

    }

    I fixed that.. Try destroy the game object collision --> " Destroy(col.gameObject.collider2D)"
     
    blox5000 likes this.
  7. vinfang

    vinfang

    Joined:
    Jul 13, 2013
    Posts:
    14
    So is this the intended behaviour or a bug? Even though the transform is changing, I consider it already inside the collider, and an enter event should only occur once.
     
  8. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    632
    It's officially a bug, I tried everything and I can't disable the target once its hit so I just uplouded a bug report, I hope it gets fixed soon.
     
    blox5000 likes this.
  9. barm

    barm

    Joined:
    Dec 3, 2013
    Posts:
    2
    Same problem.
     
  10. vinfang

    vinfang

    Joined:
    Jul 13, 2013
    Posts:
    14
    What's the name of the bug report you submitted. I saw one with your reply in it but its status is said to be fixed.
     
  11. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    632
    case # 579005: OnTriggerEnter2D fires multiples times in the same collision.
     
  12. maaizelahi

    maaizelahi

    Joined:
    Feb 10, 2014
    Posts:
    2
    Same problem
     
  13. maaizelahi

    maaizelahi

    Joined:
    Feb 10, 2014
    Posts:
    2
    Which version is this issue fixed or how to fix this issue?
     
  14. Deleted User

    Deleted User

    Guest

  15. Looking4Game

    Looking4Game

    Joined:
    Aug 21, 2013
    Posts:
    16
    Using version 4.3.4, still remain.
     
  16. Utsukurushi

    Utsukurushi

    Joined:
    Jan 5, 2014
    Posts:
    1
    lol still happening