Search Unity

Question argument 3 may not be passed with the out keyword

Discussion in 'Scripting' started by maxpanic, Jan 15, 2022.

  1. maxpanic

    maxpanic

    Joined:
    Dec 18, 2021
    Posts:
    5
    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:
    257
    Physics.CapsuleCast return a bool not a RaycastHit type. The result is true or false.
     
    Last edited: Jan 15, 2022
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    totaltech33 likes this.
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,990
    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.