Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rigidbody2D.constraints. Apparently doesn't exist. Missing directive?

Discussion in 'Scripting' started by Bionicle_fanatic, May 11, 2016.

  1. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Code (csharp):
    1. GetComponent<Rigidbody2D>().constraints.FreezePositionY();
    So... Missing directive?
     
  2. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    It seems the syntax goes about:
    Code (CSharp):
    1. GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionY;
    If it complains about "constraints" you can try restarting Unity and/or Visual studio.
     
  3. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    I actually use monodev. Still. [:p]

    Is this a post Unity 5.0 feature? That would explain the missing reference.
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    While the error message is a little misleading you were getting it in the first place because your syntax was incorrect. The RigidbodyConstraints2D enum was added at the same time as Rigidbody2D and is syntactically consistent with Rigidbody and RigidbodyConstraints.
     
    Ryiah likes this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,026
    It was added with Unity 5.3.4. That said your code is still incorrect because it's an enumeration not a method.
     
    KelsoMRK likes this.
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I was mistaken. You're using an older version of Unity AND your syntax is incorrect :)
     
    Ryiah likes this.
  7. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Ahhhh... So I either have to constrain it via transform, or upgrade (Which in doing so would incur a plethora of problems).

    Thanks for the help, guys. [:)]