• 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 MapuHoB · Apr 04, 2015 at 04:15 PM · c#androidtag

Ambiguous behaviour c# script(editor vs android device)

 GameObject mainMenu = GameObject.FindGameObjectWithTag("MainMenu");
 Debug.Log(mainMenu.name);

When I run it in the editor it works fine i.e. prints the name of the go, unlike on a device, where it says

UnityException: Tag: MainMenu is not defined.

Why?

Comment
Add comment
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

2 Replies

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

Answer by MapuHoB · Apr 04, 2015 at 05:48 PM

The problem was that the tag of the gameObject could not be found on a device. And there it is another of my questions which I've already answered. I'd just delete my question but due to it having already 1 answer I cannot do it so there it is the answer to the question. Other question

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 _joe_ · Apr 04, 2015 at 04:37 PM

That's probably because your MainMenu is not set yet, you either need to wait for it to be set, or slow down your call.

Start by trying to add your code above in a function, and call this function using Invoke. If that works, that means that your Code is just too fast and you can fix it using the Script Execution Order panel.

 void Start(){
  Invoke("MyFunction", 1);
 }
 
 void MyFunction(){
  GameObject mainMenu = GameObject.FindGameObjectWithTag("MainMenu");
  Debug.Log(mainMenu.name);
 }
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 MapuHoB · Apr 04, 2015 at 04:42 PM 0
Share

Thanks for the interest but if it was that obvious I would not ask here about it. I also don't think even if it was this the problem it still isn't supposed to have ambiguous behaviour on the device and the editor. Transfer the answer as a comment if you can because I see it only as a guess of what the problem could be and not a real solution. Also I don't think waiting for 1 sec is a good idea even if this was the problem.

avatar image _joe_ · Apr 04, 2015 at 10:19 PM 0
Share

Having a static manager being called from other start functions would actually create this problem and knowing that i don't know the whole hierarchy i assumed it might be it, adding 1 seconds is just a hack to quickly see if it's a script execution problem. here's a reference: http://answers.unity3d.com/questions/939539/cant-access-a-singletons-instant.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to start Unity Android on startup 0 Answers

Binary Save on android issues 1 Answer

Sqlite RANDOM() function not working on Android? 0 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