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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

OnTriggerStay2D only worked when object selected in Scene

Discussion in 'Editor & General Support' started by drac0nic, Sep 18, 2014.

  1. drac0nic

    drac0nic

    Joined:
    Sep 18, 2014
    Posts:
    8
    Strange behavior...I have my player with a rigidbody and 2d collider. I have a large beam that has a 2d collider set as a trigger. Their layers are set to interact in Physics 2d settings.

    I have a log print at beginning of OnTriggerStay2D and logic following it. The print, the logic doesnt get fired if my player is on top of the beam...until i selected it in the unity scene viewer.

    What the hell? This behavior is crazy. I've seen this behavior before with another game mechanic i tried to implement but i ended up scrapping it because of this strange glitch. What gives?

    Anyone know why this is happening?

    Thanks~!
    Scott
     
  2. drac0nic

    drac0nic

    Joined:
    Sep 18, 2014
    Posts:
    8
    Found a solution. Make it a prefab and programmatically spawn it.
     
  3. drac0nic

    drac0nic

    Joined:
    Sep 18, 2014
    Posts:
    8
    Correction - There was a race condition on object generation that sometimes caused an exception. The exception prevents collision detection.
     
  4. drac0nic

    drac0nic

    Joined:
    Sep 18, 2014
    Posts:
    8
    Ugh!!! Nevermind... The original issue is still occurring. It works on its own erratically.

    Still though - every time i click on the object in the scene viewer, the collision detection starts working...

    What the what!!!
     
  5. drac0nic

    drac0nic

    Joined:
    Sep 18, 2014
    Posts:
    8
    Added OnTriggerEnter2D and logged it. That is getting called instead...

    Looks like I will be adding logic to set a boolean inside of both functions and call the logic i want in the update function instead.

    Hope this helps someone.