Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

2D: Setting "Ignore Tag" on Cinemachine Collision Impulse Source throws NullReferenceException

Discussion in 'Cinemachine' started by codeimpossible, Oct 5, 2018.

  1. codeimpossible

    codeimpossible

    Joined:
    Mar 27, 2013
    Posts:
    1
    Hopefully this is the right place to report a bug.

    I added a CinemachineCollisionImpulseSource to an object and set it's Layer Mask and Ignore Tag under "Trigger Object Filter". Whenever the impulse source was triggered it would throw a NullReferenceException.

    The stacktrace pointed me to line 126 in CinemachineCollisionImpulseSource.cs, in the GenerateImpactEvent method:

    Code (CSharp):
    1. 118         private void GenerateImpactEvent(Collider other, Collider2D other2d, Vector3 vel)
    2. 119         {
    3. 120             // Check the filters
    4. 121             if (!enabled)
    5. 122                 return;
    6. 123             int layer = (other != null) ? other.gameObject.layer : ((other2d != null) ? other2d.gameObject.layer : 0);
    7. 124             if (((1 << layer) & m_LayerMask) == 0)
    8. 125                 return;
    9. 126             if (m_IgnoreTag.Length != 0 && other.CompareTag(m_IgnoreTag))
    10. 127                 return;
    11. 128
    12. 129             // Calculate the signal direction and magnitude
    13. 130             float mass = GetMassAndVelocity(other, other2d, ref vel);
    14. 131             if (m_ScaleImpactWithSpeed)
    15. 132                 mass *= vel.magnitude;
    16. 133             Vector3 dir = Vector3.down;
    17. 134             if (m_UseImpactDirection && !vel.AlmostZero())
    18. 135                 dir = -vel.normalized;
    19. 136
    20. 137             // Fire it off!
    21. 138             GenerateImpulse(dir * mass);
    22. 139         }
    on line 123 there is a check done to see if the collider is a 3d or 2d collider, and then the layermask is checked against whichever collider has been passed. That check isn't done for the ignore tag. The ignore tag only checks against 3d colliders, so when using it with 2d colliders the method errors out (since "other" will be null).

    This is in cinemachine v2.2.7.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,063
    @codeimpossible Hey thanks for reporting that! You're absolutely right. Fixed in the upcoming CM 2.2.8