Unity Community


Results 1 to 6 of 6

  1. Posts
    62

    Confirmation : no cache needed for "gameObject" property ?

    Hi,

    I would like to access the GameObject of a component and there is a property for that :
    http://unity3d.com/support/documenta...ameObject.html

    Best practices advice to cache element through the Awake method, instead of using component's properties.
    Because behind the scene, property (like "transform") performs a : GetComponent call.

    But, GameObject is not even a component (inherit from Object), so I presume there is no need to cache it in a private var.

    Can you confirm that fact ??

    I am worried about performances and I need a process as cheap as possible to check the layer of an object after a RayCast. The only way I found is to retrieve the GO, then use the layer property.



  2. Location
    Denmark
    Posts
    423
    I haven't gotten around to using it yet, but I certainly will: Profiler from the wiki

    Seems very simple. Does the job and no more.
    My First Game - Looking for Feedback

    A game is a series of interesting choices.
    - Sid Meier


  3. Location
    Leamington Spa, UK
    Posts
    486
    Was wondering about this too. Normal advice is to cache components rather than use the properties over and over, but like the OP says, a GameObject is not a component, so is there any need to cache gameObject?

    [QUOTE=Nems;907412]Hi,

    I would like to access the GameObject of a component and there is a property for that :
    http://unity3d.com/support/documenta...ameObject.html

    Best practices advice to cache element through the Awake method, instead of using component's properties.
    Because behind the scene, property (like "transform") performs a : GetComponent call.

    But, GameObject is not even a component (inherit from Object), so I presume there is no need to cache it in a private var.
    Top Gear: Stunt School Revolution on iTunes

    World´s Biggest Word Search for iOS and Android

    AppyNation

    Since the UDN update my account name has been changed from andym to andymads.


  4. Location
    Lognes, France
    Posts
    1,149
    Quote Originally Posted by andymads View Post
    Because behind the scene, property (like "transform") performs a : GetComponent call.
    I thought there would be some kind of optimization regarding this (like the Lazy class in C# 4.0). Are you sure about this ?
    A lazy big fat chicken hibernating, sleeping peacefully.
    !


  5. Location
    Leamington Spa, UK
    Posts
    486
    Quote Originally Posted by AkilaeTribe View Post
    I thought there would be some kind of optimization regarding this (like the Lazy class in C# 4.0). Are you sure about this ?
    See #3 on http://docs.unity3d.com/Documentatio...imization.html.
    Top Gear: Stunt School Revolution on iTunes

    World´s Biggest Word Search for iOS and Android

    AppyNation

    Since the UDN update my account name has been changed from andym to andymads.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •