Search Unity

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.