Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

Bug Error messages in console when upcasting Collider2D

Discussion in '2D Experimental Preview' started by Jay-Pavlina, Aug 27, 2016.

  1. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    I see a lot of messages in my console that say:
    and
    It seems to happen when I upcast a Collider2D. I am specifically upcasting a BoxCollider2D to a Component and then down to a Behaviour. I can't tell exactly which cast caused the message, but I'm sure it's one of them (or both).
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    3,104
    Very strange.

    Are you sure this isn't related to using the CompositeCollider2D? We had these messages there when the Collider2D was using the Composite but fixed the cases we were seeing. Perhaps you've revealed another.
     
  3. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    The only thing with a composite collider was the tile map, and I was seeing this message from other game objects. I did see this in preview 1 a few times, but not as often.

    To be specific, I believe this line of code was causing the message:
    Code (CSharp):
    1. var behaviour = component as Behaviour;
    2. if (behaviour != null)
    3.      return behaviour.enabled = enabled.HasValue ? enabled.Value : behaviour.enabled;
    And I stopped it by doing this instead:
    Code (CSharp):
    1. var boxCollider = component as BoxCollider2D;
    2. if (boxCollider != null) {
    3.      var newValue = enabled.HasValue;
    4.      if (newValue != boxCollider.enabled)
    5.           boxCollider.enabled = newValue;
    6.      return boxCollider.enabled;
    7. }
    Doing this still caused the message:
    Code (CSharp):
    1. return boxCollider.enabled = enabled.HasValue ? enabled.Value : boxCollider.enabled;
    So it's something about enabled and possibly related to casting.
     
    MelvMay likes this.
unityunity