Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    1,815
    @codeimpossible Hey thanks for reporting that! You're absolutely right. Fixed in the upcoming CM 2.2.8