Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted argument 3 may not be passed with the out keyword

Discussion in 'Scripting' started by maxpanic, Jan 15, 2022 at 6:21 AM.

  1. maxpanic

    maxpanic

    Joined:
    Dec 18, 2021
    Posts:
    1
    Hello I am fairly new to unity and C# and am making a jump script using a Raycast. I've run into an error in this section and I don't know what it means or how to fix it

    Code (CSharp):
    1. private bool isGrounded()
    2.     {
    3.         RaycastHit raycastHit = Physics.CapsuleCast(capsuleCollider.bounds.center, capsuleCollider.bounds.size, out raycastHit, Vector3.down, 0.1f);
    4.         Debug.Log(raycastHit.collider);
    5.         return raycastHit.collider != null;
    6.     }
    it says "argument 3 may not be passed with the 'out' keyword"
    what did I do wrong?
    The error is under raycastHit in the "out raycastHit" bit

    Thanks in advance
     
  2. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    246
    Physics.CapsuleCast return a bool not a RaycastHit type. The result is true or false.
     
    Last edited: Jan 15, 2022 at 5:40 PM
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,354
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    21,292
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    1,245
    Besides the fact that the return type does not match, you actually used a CapsuleCast, not a Raycast. You probably want to use the second overload that actually has a raycasthit argument. However a capsule cast requires two points and a radius which define the capsule and an additional direction vector. The 5th parameter would be the raycasthit out parameter. So it seems you try to use the arguments that Physics.Raycast expects in a CapsuleCast. This does not work. Always check the documentation if you have issues like that.
     
unityunity