Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by max_george111 · Jan 27, 2018 at 04:51 PM · find

Why is Find() not working?

I have used the line GameObject player = GameObject.Find("Player"); but it keeps returning null, I have also tried a couple other ways of doing this but none work I just keep getting null.,I have used the code GameObject player = GameObject.Find("Player"); although it keeps returning null, I have also tried a few different ways of doing this.

Thanks for the help!

Comment
Add comment · Show 7
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 Bonfire-Boy · Jan 27, 2018 at 04:53 PM 0
Share

Do you have an active GameObject with that name, at the time you make the call?

avatar image max_george111 Bonfire-Boy · Jan 27, 2018 at 05:03 PM 0
Share

Yes it is active in the hierarchy with the same name "Player"

avatar image Bonfire-Boy max_george111 · Jan 27, 2018 at 05:20 PM 0
Share

Can you prove this? I suspect that you are wrong, but even if you are right, the process of trying to prove it might reveal what's going on.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by $$anonymous$$ · Jan 27, 2018 at 05:49 PM

Most likely, if it is returning null, then no object exists with the name "Player".

On a script of your player object, put this in Start to make sure that the player name is what you think it is.

 Debug.log(gameObject.name):

Sometimes if you do something such as spawn the player in, then the name will change to something like "Player (clone)".

Comment
Add comment · Show 4 · 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 max_george111 · Jan 27, 2018 at 06:10 PM 0
Share

It returns "Player" like expected

avatar image $$anonymous$$ max_george111 · Jan 28, 2018 at 12:19 AM 0
Share

Have you tried finding the player using tags ins$$anonymous$$d?

 Player = GameObject.FindWithTag("Player");
avatar image Bonfire-Boy · Jan 27, 2018 at 06:17 PM 0
Share

Another trick is to put Debug.Logs in OnEnable() and OnDisable() functions, to help you to work out whether or not the object is active at the time of the Find call.

avatar image Commoble · Jan 28, 2018 at 01:17 AM 0
Share

If your player object is part of the scene's initial state, you can link the player to one of your scripts in the inspector ins$$anonymous$$d of using a Find method

avatar image
-1

Answer by victorbisaev · Jan 28, 2018 at 10:42 PM

Check "Player" GameObject is active at the moment "Find" is performed.

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

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does GameObject.Find() work in ones and not in others? 1 Answer

Transform.find Does not work 0 Answers

Referencing variable from another script on another object 3 Answers

How Can I assign a gameobject via script? 0 Answers

ERROR 15,36 An object reference is required to access non-static members UnityEngine.Transform.Find(string) 1 Answer


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