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 Arthur_Gentz · May 05, 2021 at 04:30 PM · performancetagcaching

Is it okay to assign and 'un-assign' game object tags at runtime, will it come back to bite me?

Does assigning/'un-assigning' a game object's tag have some 'scene recalculation' penalty? Or can i assign/'un-assign' tags willy-nilly?

I'm working on some interactivity between objects in the scene, and the interactivity has become a great big web. The initiation of interactions relies on identifying initiates by their tags.

The methods of 'halting' interactivity between objects during certain scenarios has reached a level of complexity that I don't want to add upon.

After some thought, the simplest way forward seems to be the simple setting/'unsetting' of tags of the interaction initiating game objects. Which would allow my current setup to easily handle enabling/disabling of any number of concurrent interactions.

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 Llama_w_2Ls · May 05, 2021 at 07:23 PM 0
Share

AFAIK, tags are just meta-data assigned to a game object, that specify a reference word for a group of objects.


Assigning this meta-data would likely have a very $$anonymous$$imal impact on performance, so assigning tags on a large scale very rapidly, doesn't seem to have a major impact.


There is no scene recalculation penalty, I believe. When you use tag functions such as FindObjectWithTag or CompareTag, it reads the meta-data directly from the game object. The objects with certain tags aren't kept in some special list (afaik), and so there is no scene recalculations done.


You could try a stress test yourself that creates a bunch of empty objects, assigns random tags every update, and checks the time it takes to find a random object by tag, and see if the frame rate is impacted by this in any way, for example:

 public class StressTest : MonoBehaviour
 {
     public int Entities;
     public string[] Tags;
 
     GameObject[] EntityArray;
 
     void Update()
     {
         print(System.DateTime.Now.ToString());

         EntityArray = new GameObject[Entities];
 
         for (int i = 0; i < Entities; i++)
         {
             EntityArray[i] = new GameObject(i.ToString())
             {
                 tag = RandomTag
             };
         }
 
         var randomObj = GameObject.FindGameObjectWithTag(RandomTag);
         print(System.DateTime.Now.ToString());

     }
 
     string RandomTag
     {
         get
         {
             return Tags[Random.Range(0, Tags.Length)];
         }
     }
 }



avatar image Arthur_Gentz Llama_w_2Ls · May 06, 2021 at 06:45 AM 0
Share

Okay, thanks for the help brother. Cheers.

0 Replies

· Add your reply
  • Sort: 

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

131 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 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

Caching stacked UI Image GameObject 0 Answers

find with tag VS find with name. 2 Answers

ArrayLists or Tags? 1 Answer

Best way to store large amounts of data for random generation 1 Answer

Coin Magnet Performance Issue Mobile 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