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
0
Question by cregox · Dec 22, 2011 at 04:54 PM · dontdestroyonloadfindgameobjectswithtag

FindGameObjectsWithTag not finding a tagged object

Can't we FindGameObjectsWithTag within indestructible objects (made so through DontDestroyOnLoad)?

If that's not the issue, what could be turning the method unable to find a tagged object?

I have a tagged object perpetuated through many scenes which was working fine within each scene before, with the same FindGameObjectsWithTag... But since I've moved it into an indestructible object so it's replicated in every scene (and thus removed each instance from each scene), it stopped working. I'm a little bit at loss here, so any help is welcomed! Specially if it's answering the two questions above! :)

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 cj_coimbra · Dec 22, 2011 at 05:18 PM 0
Share

Sorry if this sounds obvious but try pausing the game (in editor) and check if your object exists in the scene with the tag you´re looking for...

avatar image cregox · Dec 22, 2011 at 05:21 PM 0
Share

@cj Pausing is too obvious, that's why it can be missed sometimes, specially by me who almost never uses it... But yeah, I've checked if the object exists. If this question stays open long enough I at least have a good reason to believe it's just bad code. - And by the way, I just checked myself the answer to the first question would be "sure can, it works fine and of course that has no relation". As expected. :)

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Aleron · Dec 22, 2011 at 05:34 PM

Without seeing your code, at any point are you setting the object inactive? FindGameObjectsWithTag only finds objects that are active in the scene, so if you are disabling them by setting them inactive, that would explain why the method no longer finds it.

As far as I'm aware, the only find method that will return inactive objects is Resources.FindObjectsOfTypeAll, which probably isn't ideal. Your best bet if the object is being set inactive is to maintain a reference to it somewhere in another script that is always active, then perform your operations on that.

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 cregox · Dec 22, 2011 at 06:02 PM 0
Share

Haha, there you go. As obvious as @cj expected, just not exactly what he touhght! Thanks!!

avatar image Aleron · Dec 22, 2011 at 06:07 PM 0
Share

You're welcome. I banged my head against that particular wall a few too many times before I learned that the GameObject.Find* methods only return active objects.

avatar image cregox · Dec 22, 2011 at 06:10 PM 0
Share

Yeah, but I'm way too stupid. I actually already knew about this issue and I even had already referenced it. :P

avatar image cj_coimbra · Dec 22, 2011 at 06:13 PM 0
Share

@Aleron we all did!!!

avatar image
4

Answer by OZAV · Feb 02, 2018 at 03:31 PM

Now from Unity 2017 v3.0 here, it does not find even active objects by the tag, for an instance "Player" tag can not be registered in the tag editor either, or found ingame anymore, and in 2017 v2 - it was all working ok ... This is why i stopped paying to unity by my studio - every odd version like V1, V3 etc of 2017 is LOADED with bugs ... It's not worth paying for.

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
3

Answer by That1phillps · Jan 03, 2020 at 06:42 AM

If Object A is labeled with tag "A" and is the child of object "B" that is labeled with the tag "B", you will not find Object A by tag. At least that has been my experience.

Comment
Add comment · Show 1 · 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 ugurberkecanunlu · Aug 20, 2020 at 03:43 AM 0
Share

you solved my problem but i dont know why it is ?

avatar image
0

Answer by Mahamed9628 · Dec 22, 2011 at 10:10 PM

Do you instantiate your object from Resources folder (or from assets)? Make sure that object's tag is setted in that folder or add script that would set tag at the start of new scene (in awake function).

Comment
Add comment · Show 2 · 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 cregox · Dec 23, 2011 at 11:07 AM 0
Share

Huh?! This has nothing to do with Resource, folders or instantiate. At least as far as I know. I never even knew we can set tags to folders, but I don't see how! Sorry to say this seems like an unfunded answer to me. Still, thanks for trying to help.

avatar image Mahamed9628 · Dec 23, 2011 at 07:03 PM 0
Share

You don't know that you can set object's tag in assets folder? For example: we have dropship that is disposed as prefab in resource folder. It has tag "ship". And when we're instantiating this dropship, it's already tagged. It's what I meant.

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

10 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

Related Questions

Trouble with deleting duplicate MusicManager 1 Answer

Get component in FindGameObjectsWithTag...? 1 Answer

Instantiating objects to create an infinite level. 1 Answer

Find object from another scene 1 Answer

DontDestroyOnLoad() does not seem to be working. 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