Search Unity

Problem with "contactCount"

Discussion in 'Scripting' started by unity_eX0g7YMiHrgSBw, Apr 9, 2021.

?

Problem with "contactCount"

Poll closed Apr 16, 2021.
  1. e

    1 vote(s)
    100.0%
  2. e

    0 vote(s)
    0.0%
  1. unity_eX0g7YMiHrgSBw

    unity_eX0g7YMiHrgSBw

    Joined:
    Nov 29, 2019
    Posts:
    1
    I have an error in the console. it tells me:

    error CS1061: Type `UnityEngine.Collision' does not contain a definition for `contactCount' and no extension method `contactCount' of type `UnityEngine.Collision' could be found

    Here is the script with the error:

    for (int i = 0; i < other.contactCount; i++) {
    Vector3 normal = other.contacts.normal;
    //FLOOR
    if (IsFloor(normal)) {
    grounded = true;
    cancellingGrounded = false;
    normalVector = normal;
    CancelInvoke(nameof(StopGrounded));
    }
    }
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Use Code Tags:
    https://forum.unity.com/threads/using-code-tags-properly.143875/

    Also, can you show us all the containing code? If that's the actual error you're getting it's reporting a weird error since UnityEngine.Collision does have a member called 'contactCount':
    https://docs.unity3d.com/ScriptReference/Collision-contactCount.html

    This leads me to believe there may be some other bizarro error occurring before hand that is throwing the compiler off from knowing the members that 'other' contains. These weird sorts of errors happen every once in a while because you have some other syntax error located elsewhere in the code. Generally (not always) you'll have 2 (or more) errors in your log and it's the first one that's throwing off this one.

    ...

    Also, there was no need for a poll. I get this is a UI design issue of the Unity forum's post. But you don't need to fill out the 'poll' section... you only do so IF you want a poll. Leaving it blank means no poll is posted. They really should change the UI to have like a checkbox for "Have a poll" that when checked it shows the rest of the needed poll inputs, and hides that when unchecked. Cause people constantly post unnecessary polls in their posts here.