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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Feedback Can I name by Rigidbodies "rigidbody" yet?

Discussion in 'Scripting' started by Baste, Oct 23, 2020.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,196
    The built-in rigidbody, camera, light, animation, renderer, audio, etc. properties in Component was deprecated in Unity 4 or 5, but they're still there, half a decade later, with [Obsolete] markers. This means that there's a ton of very useful variable names that I can never use, since they conflict with a bunch of other stuff.

    Why are they still there? It's not for backwards compatibility, since the properties has been throwing exceptions for years. Is there any reason why you don't just delete them?
     
    matkoniecz, SINePrime, mutp and 11 others like this.
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    677
    They need those there to be able to run the API upgrader AFAIK, but yeah, I would say that it would be better if they just require to jump between each year version before updating to the latest one
     
    PraetorBlue likes this.
  3. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    258
    Can you provide some examples where this causes problems or errors? You can use the "new" keyword on a field to use those names, and using them within a method just results in a warning (which can be suppressed in several ways).

    Absolutely not disagreeing: these should've been removed ages ago, but I'm curious about the situations you're encountering issues with.
     
  4. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I'm bit on a fence on removing things that don't matter for most. I've always liked that I can pick any ancient Unity project and it does give me feedback on what I should change to make it work again when I try to run it on latest version. For example there's one Unity 3.x project that I can still make work on 2020 cycle just by following the hints from the obsolete messages.
     
    cxode likes this.
  5. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I use a cached MonoBehaviour which was originally written when these properties existed in Unity but now that they're obsolete I face two problems:

    1. I get warnings every time I build. If I use the "new" keyword, it tells me I don't need to. If I don't, it tells me I do need to.

    2. If I upgrade a project to a new Unity version, the API upgrader changes my valid property code to e.g. myGO.GetComponent<RigidBody>() instead of just myGO.rigidbody. In other words, it makes my code perform worse by doing lookups every frame rather than accessing the cached references!

    If Unity would just remove these obsoleted properties then my cached MonoBehaviour script would work fine.
     
    Last edited: Oct 24, 2020
  6. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    That doesn't sound like a good argument for keeping obsolete properties like those, just to be able to open old projects and know when something needs to be replaced. If the obsolete properties are removed you will know either way. It doesn't seem fair that the ability to open old projects would take precedent over being able to use those names as if they're keywords. They used to matter at a time when a transition was happening, but today that point is moot.
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,196
    I mean the situation I'm encountering issues with is that I have to add the "new" keyword and suppress warnings.

    They also strip the properties out in builds, so you end up with new warnings about "new keyword is not necessary" there, which is just fantastic.
     
  8. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    I've been wanting to make a post about this annoyance for ages(thanks for doing what I have been too lazy to do). Couldn't this just be an editor script, in a similar vein to how you update materials to either renderpipeline from built-in, instead of being these "reserved keywords"?
     
  9. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    JoNax97 and Peter77 like this.
  10. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
  11. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    We have not removed these properties yet because they are required for ApiUpdater to work.

    Since these properties were heavily used we would like to keep support updating them to make it easier to migrate old code (keep in mind that there are lots of educational material, tutorials, videos, projects, etc out there that still references these properties).
     
    rz_0lento and Joe-Censored like this.
  12. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,196
    But unless you have an absurdly simplistic project, updating from the last version where these were supported (4.7, I believe) to 2020 won't work anyway.

    I'd really love to have a switch I could turn on to say "I'm a professional developer, not some beginner hobbyist making their first game with a tutorial from 2015 for some reason, please let me use these variable names".
     
    matkoniecz, thelebaron and JoNax97 like this.
  13. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    I'm confused. What's the purpose of marking them as obselete if they are still being supported? Why discourage their use?
     
  14. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    They're not supported by the engine, they're supported by the script updater.
     
    AdrianoVerona_Unity likes this.
  15. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317
    the goal is not to get it working, but to ease this process

    It is a little bit more complicated than that (for example, you may have an existing, unsupported assembly, referencing these members) but, yeah, it may worth exploring this idea.
     
    matkoniecz likes this.