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. Dismiss Notice

Instance or getComponent?

Discussion in 'Scripting' started by Dzxyan, Jun 12, 2014.

  1. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    Instance or getComponent
    which one is better for calling?

    I wanna know which call is more better or have any better way to call?
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    What is Instance?
     
  3. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    it a kind of singleton
     
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
  5. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
  6. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    yeah, don't see why not.
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    I'm pretty certain that using SendMessage() a lot can have a serious impact on performance and is best avoided.

    I would suggest using GetComponent() in the Start() function to inialise a local variable which can then be used to reference the object throughout the rest of the script. You could also use public static variables, which in general is less desirable, but under the right circumstances can be quite useful.