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 /
avatar image
0
Question by rebelarcher · Apr 07, 2018 at 02:08 PM · tagtagging

Set a Tag Multiple GameObject[]

How can i set a tag multiple GameObject[] i tried this but its not work.

public GameObject[] randomSpawnes;

void SetTag(string tag ){

     GameObject[] randomSpawnes = GameObject.FindGameObjectsWithTag (tag);
     foreach (GameObject target in randomSpawnes) 
     {

         target.gameObject.tag ="BlaBla";

     }            
 
 }
Comment
Add comment · Show 5
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 Priyanka-Rajwanshi · Apr 07, 2018 at 02:20 PM 1
Share

Tags should also be set up in the tag manager before use. Is "blabla" assigned in Tag manager?

avatar image Hellium · Apr 07, 2018 at 02:21 PM 1
Share

What "does not work", are you sure BlaBla is an existing tag in the editor? You can't create tags at runtime. The tag must exist in the list of tags of the Editor.

avatar image rebelarcher · Apr 07, 2018 at 02:30 PM 0
Share

Yes blabla is assigned in manager

avatar image Priyanka-Rajwanshi rebelarcher · Apr 07, 2018 at 03:03 PM 0
Share

Did you try debugging? What is the length of randomSpawnes? Also you have declared randomSpawnes twice, once locally and other globally.

avatar image rebelarcher · Apr 07, 2018 at 07:17 PM 0
Share

Thanks for your comments. I solved it.

1 Reply

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

Answer by Koyemsi · Apr 07, 2018 at 04:22 PM

Hi. So you're trying to re-tag objects that were already tagged ? Or did I understand wrong ?

Anyway, I think your script can't work because :

  • you declared twice randomSpawnes as an array of GO

  • you never call the SetTag() method which does the tagging.

Your script should be something like that :

 public class Retagging : MonoBehaviour {
 
     public GameObject[] randomSpawnes;
 
     void Start () {
         SetTag ("blabla", "jobijoba");
     }
 
     void SetTag (string oldTag, string newTag) {
         randomSpawnes = GameObject.FindGameObjectsWithTag (oldTag);
         foreach (GameObject target in randomSpawnes) {
             target.tag = newTag;
         }            
         Debug.Log (randomSpawnes.Length + " objects found and re-tagged");
     }
 }
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 rebelarcher · Apr 07, 2018 at 06:31 PM 0
Share

Thanks for you comment. Its work .

avatar image Koyemsi rebelarcher · Apr 07, 2018 at 08:57 PM 1
Share

You're welcome.

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

78 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 avatar image avatar image

Related Questions

Match 3 game getting the colour of the match 1 Answer

nullReferenceException when comparing tag in a search for a specific parent. help. 1 Answer

Making object switch between two tags every 3 seconds 3 Answers

Using FindGameObjectsWithTag to print text 1 Answer

Raycast isn't working when with tag 2 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