• 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 UpheavalEntertainment · Dec 13, 2016 at 03:30 AM · stringtagtagssetactivefindgameobjectwithtag

Swapping a tag for string not working, replacing a tag with a public string, help.

hello, what am i doing wrong? sorry im new but i was sure this was going to work, thanks. (im swapping the tag for a string?)

 public string Hello;
 
 void Update()
 {
 GameObject.FindGameObjectWithTag(Hello).SetActive (false); //goes wrong here
 }

Hello,I was trying to make it easier for me so instead of making 100's of scripts to find a gameobject with a tag, thought i would use string instead, so i can edit it outside the script. here's my code, but it doesnt work? anyways around this. thanks

 public string OUTSpeechBubble_NAME;
 
 void Update()
 {
 GameObject.FindGameObjectWithTag (OUTSpeechBubble_NAME).SetActive (false); //this doesnt work
 }
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 getyour411 · Dec 13, 2016 at 03:31 AM 0
Share

Please use the 10101 button around your code snippets to format them; I corrected these for you.

avatar image UpheavalEntertainment getyour411 · Dec 13, 2016 at 06:36 AM 0
Share

wait how? and thanks, sorry i noticed i repeated the question above

1 Reply

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

Answer by sumitb_mdi · Dec 13, 2016 at 04:28 AM

Make sure 1. You have assigned this public variable a value in the inspector. 2. You actually have a game object with that tag name in your game.

To check the first point, you can simply put a Debug.Log statement. To check the second point, you can simply put the double-quoted raw string in that line and check if it is working.

PS: Don't use FindGameObjectWithTag method in Update loop. This is a heavy method which checks each and every game object. Sooner or later you will find yourself in Performance issues.

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 UpheavalEntertainment · Dec 13, 2016 at 06:38 AM 1
Share

hey, thanks. i dont $$anonymous$$d update loop as it only runs sometimes. thanks for the reply i figured it out ^^

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

difference between GameObject.FindGameObjectWithTag(Tag tag) and GameObject.FindWithTag(Tag tag) 3 Answers

Prefab tag bug 0 Answers

Changing tagged objects in script 1 Answer

Set reference to multiple gameobjects based on tag category / multiple tags? 2 Answers

How to assign a tag to multiple parts of a Model 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