Search Unity

Problematic OnTriggerStay2D when called from a Script with Rigidbody 2D.

Discussion in 'Physics' started by tranos, Feb 25, 2015.

  1. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    I have two objects with "rigidbody 2d" attached.
    In both "IsKinematic" is false , "Sleeping mode" is "Start Awake" ,in one of two "fixed angle" is "true" and "Collision detection" is "continuous".

    When I call "OnTriggerStay2d" and I am already in the trigger, it does not work .
    But when I change "Sleeping mode" ,in either of the objects , to "Never Sleep" it works perfectly.
     
    Last edited: Feb 26, 2015
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    Seems to work for me.. which unity version you are using?
     
  3. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    4.6.2f1.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Could you explain exactly what you mean by this? You seem to be saying that YOU are calling it rather than Unity which I don't understand.

    If two things are overlapping then you'll get OnTriggerEnter2D then a continuous stream of OnTriggerStay2D until both objects are sleeping. The reason we stop reporting on a contact between two objects that are sleeping is for performance reasons; a huge number of collision/trigger stay callbacks can be produced otherwise and mostly it's redundant. If either one of the objects is awake, we'll continue to report contacts.

    Hope that helps.
     
  5. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    I mean that a script calls "OnTriggerStay2d" that is attached on one of the two gameobjects (the Player).When some conditions are met, it does something.

    But it doesnt work although the conditions are met.So ,I 've written a "Debug.log" after the "OnTriggerStay2d" and it debugs only when the Player enters or moves in the trigger area.When he stays still it does not.It worked before...

    Also, when the Player stays still in an area that has a trigger but doesn't have a rigidbody , "OnTriggerStay2d" is called as long as I am in the trigger area..
     
    Last edited: Feb 26, 2015