Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Collider Trigger Not Working

Discussion in '2D' started by KingsleyD, Mar 21, 2020.

  1. KingsleyD

    KingsleyD

    Joined:
    Jan 12, 2020
    Posts:
    7
    Whenever I put a sprite into my scene everything is normal. I put a box collider 2d it's normal. But as soon as I check the trigger box it changes nothing. It acts as if it was never put as a trigger and it just acts like a normal box collider. I add a scene trigger script to the object and it doesn't trigger. Can anybody help me?
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    Hey, could it be that there's another non-trigger collider on a parent or child GameObject?
    Could it be that the trigger checkbox is getting unchecked from some script?
    Are you instantiating this object at runtime and perhaps the prefab has a different setting than the instance?
    It would be helpful to see a pic of the collider's settings.
    What do you mean by a "scene trigger" script?
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    What did you expect to change? This sounds like you click it and then instantly expect something to happen. You should clarify the steps you are taking here.

    Again, what is "acts like a normal box collider"? If you're saying that it is bouncing off things and/or things are bouncing off it then I'd be amazed because that would mean that the simple property that sets something as a trigger is broken.

    You should post code because everything so far is very vague and you're using your own terminology here. So you're using "OnTriggerEnter2D()" on the script on the same GameObject?

    As mentioned above, post some code, show some settings and state what your expectations are.
     
  4. KingsleyD

    KingsleyD

    Joined:
    Jan 12, 2020
    Posts:
    7
    By "Normal Box Collider" I mean that it collides with objects. It's the default state. When I set it as trigger by checking the box it doesn't act as a trigger. The scene trigger script goes like this:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class scenetrig : MonoBehaviour
    7. {
    8.     private void OnTriggerEnter2D(Collider2D collision)
    9.     {
    10.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    11.     }
    12. }
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    So triggers are not broken so it has to be something with your set-up so we need to figure out what that is. Maybe you can describe where this script above is and what else is on the GameObject. Then, what Rigidbody2D/Collider is touching it. Finally, I presume you've checked that the OnTriggerEnter2D is not actually being called by debugging that (checking that the load scene isn't silently failing).
     
    Last edited: Mar 23, 2020