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. Dismiss Notice

Question Collider2D "darkens" in playmode and then stops working

Discussion in '2D' started by microbrewer, Dec 18, 2022.

  1. microbrewer

    microbrewer

    Joined:
    Jun 6, 2020
    Posts:
    12
    Hi everyone,
    I'm Unity 2021.3.15f and I noticed that in the scene view during play mode, the geometry for my Collider2Ds seems to "darken" or "fade" out sometimes. In particular, while I move my character and for a short time after, its colliders shine in bright green (left picture), then fade out (right picture):
    Collider Brighter.png Collider Faded.png
    The thing is, I noticed that trigger callbacks (OnTriggerEnter2D etc) aren't always called properly while the colliders are in this faded state.

    Can anyone explain what these different "shades of green" mean an when a collider2D changes between them?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    It indicates it's gone to sleep. It doesn't "stop working:, it's sleeping.

    That's incorrect. The body won't sleep if there's a new contact or a contact finishes because it has to be moving or something in contact with it has to be moving for this to happen. What does stop happening is that all "Stay" callbacks stop to improve performance.

    If you do anything to the body such as add a force or if it moves or comes or goes into contact it automatically wakes. You are worrying over something that is perfectly normal. It doesn't affect functionality and only increases performance.

    You can configure the colours in the settings too.
     
  3. microbrewer

    microbrewer

    Joined:
    Jun 6, 2020
    Posts:
    12
    Ok, thanks. I think I understand this a bit better now.

    But here is my specific use case: I use a global collider pool to recycle collider objects. When I take a collider out of the pool, I child it to the rigid body, change its geometry, then re-enable it. So as I don't add any force etc, this process doesn't "wake up" the rigid body. Makes sense so far.

    However, if the collider is in contact with another when it is re-enabled, none of my attached TriggerEnter2D callbacks are called, unless the body was already awake at that point in time, in which case everything works the way I would expect it to.

    EDIT: I tried waking the RB manually via RB.WakeUp(). Then everything seems to work the way I would like. :)
     
    Last edited: Dec 20, 2022