Search Unity

rigidbody is obsolete?

Discussion in 'Scripting' started by chipp_zanuff, Dec 27, 2016.

  1. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28
    i wanna ask, in my video tutorial, it's used rigidbody but when i try to use it, it says the following error msg:

    what am i supposed to use and do?
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    yes, it is. use GetComponent<Rigidbody>() instead, literally what it says
     
  3. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    In eariler versions of Unity, Monobehaviour had a property called "rigidbody". later, in a desire to make scripts more decoupled, they depreciated the property (not every monobehaviour needs a rigidbody) so the variable still exists, but should not be used.

    In your scripts don't call your variable "rigidbody" but something like "rb" since rigidbody already exists in the parent class and was depreciated.
     
    Kiwasi and TaleOf4Gamers like this.
  4. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28
    fyi, i watch



    is it an old tutorial?
     
  5. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Please stay away from tutorials that are two years old in the future. It might not be much, but in two years a bunch of updates happened (I'm not sure, but the new UI system might be less than 2 years old)
     
  6. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28
    @gorbit: can you suggest several decent tutorials? (either ebooks or videos)
     
  7. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Go to the learn section of this page, there are the official tutorials
     
  8. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28
    @gorbit: is there's anything else?
     
  9. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    There are a lot of good tutorials, just google them, but if you want something, that will surely work, you need to do those
     
  10. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    chipp_zanuff likes this.
  11. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28
  12. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    rigidbody was a shortcut they removed.

    So just replace it with GetComponent<Rigidbody>() as mentioned, but you should cache it at the top.

    Code (CSharp):
    1. public class Whatever : MonoBehaviour {
    2.  
    3.     private Rigidbody rb;
    4.  
    5.     void Awake()
    6.     {
    7.         rb = GetComponent<Rigidbody>();
    8.     }
    9.  
    10.     void Function()
    11.     {
    12.         rb.AddForce //......etc
    13.     }
    14.  
    15. }
     
  13. chipp_zanuff

    chipp_zanuff

    Joined:
    Jul 26, 2016
    Posts:
    28