Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

rigidbody property is deprecated?

Discussion in 'Scripting' started by Nanako, Mar 11, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047


    Firstly it says [deprecated] there
    And also, i don't remember this property ever not returning a rigidbody, what gives?
     
  2. plasmabazooka

    plasmabazooka

    Joined:
    Mar 8, 2015
    Posts:
    70
    Try to use GetComponent
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    yes getComponent works fine. thats not really my point
     
  4. Mr-Mud

    Mr-Mud

    Joined:
    Mar 8, 2015
    Posts:
    37
    The people of Unity wanted to update their API; as can be read in this blog post. The Rigibody class is now supposed to reside in a different DLL, so the physics engine does not need to be included if you are not using it. As a result its type is not known in The UnityEngine namespace: so therefore it now returns Component.
     
    Dmitry-Veniaminovich likes this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yes. It was deprecated in 5.0. Reason for this was to break up the engine into modules that were not dependent on each other. Having a Component.rigidbody means that Component is dependent on the physics system. Bad design. All of the shortcut methods were deprecated, except .gameObject and .transform.

    In practical terms this was made worthwhile by WebGL. All other platforms have the user download the engine only once. With WebGL the player has to download the entire unity engine every time. So if you can strip out the modules that aren't ever used in the game you can make loading times much more efficient.
     
    Dmitry-Veniaminovich and Mycroft like this.
  6. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    This sounds like a disastrously bad design. Why then, would we want to use webGL?



    Also from the blogpost:

    this interests me. How. has anyone written it already?
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    All the internal properties like rigidbody, camera, renderer etc are depreciated because previously they were all using getcomponent under the hood = slow.

    So simply cache in awake or start and use a variable, or derive from a class of your own which sets these back up and caches them ie rb, cam, rend etc.

    This is a good move as opposed to either storing everything on everything (duh waste ram) and looking it up (duh waste performance).

    So you get performance and ram back now.
     
    Nanako likes this.
  8. Deleted User

    Deleted User

    Guest

    there is probably someone out there that has done it already but I have never ckecked because I wouldn't use it anyways. UT did a really good change here.
    However implementing it your self is easy to do
    Code (csharp):
    1. public class ExtendedMonoBehaviour : MonoBehaviour
    2. {
    3.     private new Rigidbody rigidbody { get { return GetComponent<Rigidbody>(); } }
    4.     // and so on
    5. }
     
  9. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Seems equally trivial and consistent to just use the new way.
     
    KelsoMRK likes this.
  10. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    I have.

    I called it MonoBehaviourClassic and I submitted it to the Unity Asset Store last week as a free asset package. It covers all of the old GetComponent shortcuts as well as some new ones. I also implemented component caching (so you're not calling GetComponent under the hood every time you use the properties) and compiler directives to selectively include/exclude properties that you have no interest in.

    It hasn't been approved yet, but I'm releasing it under an MIT license. So here you go. It's pretty self-explanatory but I made a manual anyway. :)

    Hope it helps!
     

    Attached Files:

    ChrisRob and Nanako like this.
  11. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    i love you <3
     
  12. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    To avoid having to use a plug-in. The biggest reason to avoid plug-ins are the teams using Unity for web display; many companies don't allow their employees to use plug-ins at all. We've spent years convincing companies that the Unity plug-in didn't represent a security risk to their networks. Moving to webGL will allow Unity access to professional web developers.
     
  13. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    Isn't this an entorely specious and semantic argument? things have to be downloaded in order to play it anyways. What exactly is the functional difference between downloading a web player once, and downloading an engine every time?
     
  14. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    He just said - because one is considered a plugin and the other isn't. Clearly you've never had to deal with an IT Security department in a corporate environment before.

    Having to download a plugin before you can use something on the web is also terrible user experience and will cause your adoption to plummet through the floor (ie - no one wants to do it and few people will).
     
    Mycroft likes this.
  15. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Just learn the new way, of getting and caching thigns when they are actully needed.
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As mentioned above, the main point of removing the shortcuts is to help make the engine more modular, so in fact it won't be necessary to download the entire engine.

    --Eric
     
    Mycroft likes this.
  17. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Bunch of reasons why Unity is going to WebGL over Web Player.

    Web Player says "Please install this plugin". WebGL just plays the game in the browser. Many people are reluctant to install plugins, and just move on. Especially if its not the most reputable website asking you to run it. Asking "are you sure" and having the security system pop up with a warning is not a good look for most people.

    Corporate networks don't allow users to download random plugins. For good reasons. You can do far more with a plugin then with WebGL. WebGL is pretty much limited to running on the webpage its on. A malicious plugin can do all sorts of things inside your browser. Corporate security seldom finds the idea of adding a game plugin to the whitelist attractive.

    And lastly all of the major browsers have announced plugin support is ending soon. WebGL will soon be the only option to publish to the web. In practice its already difficult to impossible for Chrome users to use the WebPlayer.
     
  18. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    It's weird we had to get so far in this thread before getting to the real motive behind switching to WebGL (and all of the design changes in 5.0 that were triggered by this decision, specifically the one in this issue and the invention of IL2CPP - because within the new couple of years, plugins won't work, period. On any browser.
     
    Kiwasi likes this.
  19. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Saying "because IT departments say so" is a little inaccurate. The IT guys have a very good reason for this, as do the browser developers, and it's the same reason: native plugins are fundamentally insecure, while Javascript (which WebGL runs on) can be sandboxed.
     
    Kiwasi likes this.
  20. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Of course. I wasn't insinuating that they were doing it for no reason. Only that typically "no means no" and convincing them otherwise is difficult.