- Home /
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
}
Please use the 10101 button around your code snippets to format them; I corrected these for you.
wait how? and thanks, sorry i noticed i repeated the question above
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.
hey, thanks. i dont $$anonymous$$d update loop as it only runs sometimes. thanks for the reply i figured it out ^^
Your answer
Follow this Question
Related Questions
difference between GameObject.FindGameObjectWithTag(Tag tag) and GameObject.FindWithTag(Tag tag) 3 Answers
Tag is not defined, when it has been manually created? 1 Answer
send message to all objects of a certain tag 1 Answer
FindGameObjectWithTag failing 1 Answer
setActive on object in separate scene 2 Answers