Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ina · Apr 11, 2011 at 04:01 PM · getcomponentfindstructuretheory

GameObject.Find() GetComponent() based assigns vs others?

This is a theory question of sorts, where I am trying to learn more about different types of programming languages and their structure.

In Unity, the GameObject.Find() and GameObject.GetComponent() are used to designate objects - what is this kind of system called, and what are some other systems? How do they compare to each other? Is Unity's Find, GetComponent and such more preferable than others? How might Unity be improved to not use Find, GetComponent?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessy · Apr 11, 2011 at 04:33 PM 0
Share

Not appropriate for this site.

avatar image ina · Apr 11, 2011 at 06:21 PM 1
Share

It's a question in need of answers, though an open-ended one. $$anonymous$$y the "community wiki" checkbox isn't enabled on this stack...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kennypu · Apr 11, 2011 at 08:28 PM

Although I do not know how the underlying code works for those methods, those are basicly known as 'setters' and 'getters', or mutators and accessors. Its part of what is known as Object Oriented Programming (OOP). As far as performance goes, it is usually better to directly access those properties, rather than accessing it with the likes of getters and setters, but that can cause problems as well.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by scriptocalypse · Apr 11, 2011 at 09:02 PM

In my admittedly limited experience, I recently smashed several tutorial projects together and did a lot of code conversion to C#. In doing so I noticed a disturbing amount of code that looks like this:

//In every update cycle.... void Update(){ GameObject foo = GameObject.Find("Foo"); BarComponent bar = foo.GetComponent<Bar>();

  GameObject[] gos = GameObject.FindWithTag("AllFoos");

}

My smashup, when tested on my Droid 2 was getting something on the order of 18fps on average after a certain point. When the object graph was relatively small, I didn't have nearly so many problems with performance. So what I decided to do was pre-cache those values in void Start() instead of accessing them every update I immediately shot up to an average of 25fps. It really makes a difference, and the more gameobjects you have in your scene the bigger the difference will be.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Finding things with Raycasthit 1 Answer

Referencing to an initiated Text 1 Answer

Need an advise, how to find all objects with a specific name and a specific script? 2 Answers

Instantiated Prefab using its transform and object on other scripts 1 Answer

Better to assign components to variables or reference directly each time 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges