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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Cached values

Discussion in '5.4 Beta' started by laurentlavigne, Jul 23, 2016.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,793
    What Get* or .thing are cached?
    It seems GetComponent is cached, I see in deep profiler 12K GetComponent only eating up .57ms
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,569
    Nothing is cached.
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,793
    Ok - very fast for non cached!
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,569
    That's because people kept microbenchmarking it, so we heavily optimised it :)
     
    laurentlavigne likes this.
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,793
    I shall keep it un-cached then, make that optimization shine!

    What else did they super optimize?
     
  6. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    292
    @superpig Slightly off topic, but are you going to remove the deprecated shortcuts to GetComponent(), such as .rigidbody, .renderer etc.? They were deprecated ages ago yet still clutter my intellisense.. :) (haven't actually checked if they're still in 5.4)
     
    laurentlavigne and Ostwind like this.
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,793
    Also, the opposite of @mh114, is it possible for us to add those shortcuts back by overloading object - not super familiar with c# niceties but I've been overloading Vector3 with custom methods...
     
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,569
    At some point, yes, but not just yet. They're marked with the ObsoleteAttribute, though, so I'm a little surprised they're showing in Intellisense for you - I thought it would not show Obsolete members.

    You mean extension methods? There's no 'extension properties' in C# (yet) so you wouldn't be able to add them back exactly as they were, but you could do them as methods (gameObject.GetRigidbody(), etc) if you wanted to.
     
  9. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    292
    I'm using Visual Studio 2015, and sure enough they appear in the list all times. Marked with deprecated, but only on the info when selected. Doesn't look like there's a way to disable them showing up in there, either.
     
  10. Tuni

    Tuni

    Joined:
    May 24, 2013
    Posts:
    74
    And you can't name your variables rigidbody or renderer without getting a warning.
     
    Ostwind and mh114 like this.
  11. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,805
    Yeah I also hate them appearing in my lists and preventing me to use the most logical names for my variables.
     
  12. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    309
    Hi. Unfortunately these obsolete properties are required for the automatic update process to work. He have been playing with alternatives to allow us to remove them but so far we could not find one that would work.

    Regarding VS displaying those members in intelesense, unfortunately VS will show them unless they are marked with EditorBrowsableAttribute (which some of them, but not all, are).
     
  13. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    292
    Well, in my opinion everyone has had plenty of time to got rid of those deprecated accessors. Not to mention the fix couldn't be easier (use GetComponent instead). So personally I'd go for a breaking change in this case.
     
  14. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,805
    I guess there are still a lot of people working with Unity 4 with their old projects and then there is Asset store full of packages with no Unity 5 support (art packages with small interaction/camera fly scripts, etc.) so the updater is still probably needed for some time.

    However personally at this point of Unity 5 lifetime I would rather update old code manually and get rid of the obsolete stuff so I can re-use the variables.
     
  15. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    309
    Removing the ability to auto-update these members would make it harder for users new to Unity; also, it would invalidate tutorials, manuals, blog posts, code samples, etc.

    Adriano