Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

All The Tags! - Unity3D Tags Replacement (Multiple tags, better performance, etc!)

Discussion in 'Assets and Asset Store' started by Pigeon Coop, Dec 6, 2014.

  1. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    All The Tags!
    Asset Store ($10) | Documentation


    All The Tags! Replaces the built in tagging system in Unity3D. It’s sole purpose is to allow you to add more than one tag to any object, however there other benefits too! It performs substantially better than doing a standard string compare, generates no garbage and allows you to customize your tags with colours to stay organized!

    Screenshots




    FAQ

    The documentation mentions that the AllTheTags methods never return null? What do they return if it doesn't find any objects?

    It just returns an empty collection of objects. This way you don't have to do null checks everywhere.

    Code (CSharp):
    1. var taggedObjects = Tags.FindGameObjectsWithTag("MyTag");
    2.  
    3. foreach(var taggedObject in taggedObjects)
    4. ...
    Instead of

    Code (CSharp):
    1. var taggedObjects= Tags.FindGameObjectsWithTag("MyTag");
    2.  
    3. if(taggedObjects!= null)
    4. {
    5.  
    6. foreach(var taggedObject in taggedObjects)
    7. ...

    Do I need to ensure every GameObject has an AllTheTags component before I pass them along to an AllTheTags function?
    No - AllTheTags is very rebust - if an object does not have an AllTheTags component, it will add it for you when you try to check that GameObjects tags. It won't throw any errors at you.

    So you could safetly do Tags.HasTag/etc on any object in your project. Whether they have an AllTheTags component or not doesn't matter!

    Simply add the 'AllTheTags' component to any object that needs one via the inspector, and the rest will handle itself :)

    If an object does not have an AllTheTags component, it is considered to have 'no tags'.

    Tags.FindGameObjectsWithTag(string tag) - how exactly do I use it?
    By default, the FindGameObjectsWithTag returns a ReadOnlyCollection of objects. This is just like a List except that you can't add objects to the list or remove objects from it! The reason it is done this way is because most of the time all you want to do with the result of FindGameObjectsWithTag is iterate over all of the objects and run some code on each object. A ReadOnlyCollection is fine for this task, and it means that we don't have to allocate a new List of objects in memory to hold the result of every FindGameObjectsWithTag operation. Nice and efficient. :)

    You can iterate over a ReadOnlyCollection with a foreach statement, exactly the same as List.

    If ReadOnlyCollection doesn't fit your requirements however, you can still get a normal List out of the results fairly easily so you can do whatever you like with the results!

    Code (CSharp):
    1. List<GameObject> myList = new List<GameObject>( Tags.FindGameObjectsWithTag("MyTag") );
     
    Last edited: Jan 2, 2015
    Cogent likes this.
  2. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Coming very soon is an update to quickly fetch all of the objects in the scene with a certain tag. Works much faster than the built in solution to Unity! I will release some figures soon :)

    For now though.. Unity vs AllTheTags! when checking to see if an object has a certain tag.

    I checked to see if a GameObject was tagged as 'MainCamera' 2 million times. The GameObject was tagged as MainCamera using the Unity tag system, and it was tagged as MainCamera and 3 other tags as well using All The Tags.

    Unity3D took 568~ ms to perform this operation and generated 72.5 MB of garbage (GC Alloc).
    All The Tags! took 412~ ms to perform this operation and generated no garbage.

    As you can see the checks are very quick and very clean. You can have lots of tags on every object in your game and you can check the game objects tags instead of its components to try and figure out what type of object you are dealing with!

    If your 'bullet' hits the a GameObject, how do you know if your bullet should deal damage to the object? You could do a GetComponent on that GameObject and check to see if it has a 'Damagable' component, or you can just check its tag to see if you should apply some damage to that object and only do a GetComponent when needed.
     
  3. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Hey look! Vouchers :)

    If you like it, don't forget to rate us and leave a comment here! Enjoy!

    - All Taken -
     
    Last edited: Dec 8, 2014
  4. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    I got the middle one (ASV-77MU-NLAJ-XJPX-JWRF-RC6Y). Thanks!

    I have your "Better Trails" is the reason this asset caught my eye. If I like it I'll buy one of your other assets (could use the NavMesh 2D) because it feels weird getting something for free.
     
  5. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Don't feel weird! You can always 'pay us back' by letting us know what you think! We'd love some feed back and we'd love to hear what type of features you all would like to see - that's why we are giving away a few copies! :) Right now AllTheTags! is in its infancy, but we've got a strong foundation to build up on!

    As mentioned before, I am about to submit an update for AllTheTags. We're adding a function to fetch all the GO's in the scene with a particular tag and it is very quick compared to Unity's built in function (FindGameObjectsWithTag)! Thinking about adding some other helper methods too, like a 'FindGameObjectsWithTagAroundPoint'.
     
  6. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    Was too late for the Vouchers. Will get it soon.
     
  7. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,416
    Uh, this could come in handy. But is it compatible with Unity 4.3.X ?
     
  8. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    I imagine it would work fine, but I'll download version 4.3 and find out myself. Will let you all know in a few hours (I am not home right now!).

    If it works fine I'll make sure I submit the next update under 4.3 :)
     
    BTStone likes this.
  9. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    @BTStone I am making use of [DisallowMultipleComponent] which is 4.5.X and up.

    I think I can get rid of it and just do some checks to prevent multiple copies of the AllTheTags component on one GO. Should be able to make it work fine with 4.3 in the next update

    If you end up buying it before the update hits the store, just remove that attribute from AllTheTags.cs and it will all work fine. Just avoid adding the component more than once to a GO! :)
     
  10. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,416
    Great, as soon as the update hits the store I'm on it!

    And +1 to Helper-Functions! :D
     
  11. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Ok, Submitting an update for the asset store team to review now! This update introduces the FindGameObjectsWithTag method. Substantially faster than Unity's built in method. AllTheTags! will internally keep a record of all GameObjects and associated tags that exist within your scene. Makes it really easy and quick to find objects with tags. Here are some figures.

    100 GameObjects.
    'Test' tag applied to all GO's (Both Unity and AllTheTags!)
    1,000,000 iterations - we invoke FindGameObjectsWithTag (Both Unity and AllTheTags!) a million times.

    Unity3D took 2500~ ms to perform this operation and generated 405~ MB of garbage (GC Alloc).
    950~ ms was spent on GC.Collect, 1550~ ms was spent on the actual operation

    All The Tags! took 215~ ms to perform this operation and generated 12~ MB of garbage (GC Alloc).
    30~ ms was spent on GC.Collect, 185~ ms was spent on the actual operation

    I am really excited about this update. The method really helps showcase the power :)
     
    BTStone and meapps like this.
  12. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Awesome news! 1.1.0 is live! More features soon, get it while it's hot ;)

    I've scrapped the GameObject extension methods as it was getting a little confusing..! GameObject already has some 'tag' methods, adding mine in there was a little bit too much. So now you can find all the AllTheTags! methods under the 'Tags' static class (ie: Tags.HasTag(gameObject,"tag"))

    Change log 1.1.0
    • New 'Tags' static class, will hold all AllTheTags! methods (Like HasTag, etc)
    • Extension methods are now obsolete (Use the Tags static class)
    • 2 new methods - FindGameObjectsWithTag and FindGameObjectsWithTagAroundPoint
    • Now works with Unity 4.3.X onwards
     
    meapps and BTStone like this.
  13. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Woo! We've reached 3 reviews now which means we finally have a star rating. Thanks everyone!

    Soon I'll be releasing another update to help you find tagged objects that are childed to a specific object (FindChildrenWithTag).

    Release soon and release often I guess. :) Your tags will be preserved in between updates - to update AllTheTags! In your project, all you need to do is import the newest asset from the asset store.
     
    meapps likes this.
  14. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    Thanks for the update. I am getting an error - "The namespace 'global::' already contains a definition for 'Tags.'

    It's the only error in the console, but not sure if there is a way to check what other asset might have that same namespace? I want to keep All The Tags installed and get rid of any asset that is conflicting.
     
  15. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Hey @MIK3K
    I am not sure what package it could be conflicting with. You need to open up your MonoDevelop and search your entire project for "class Tags". It should reveal to you the files that define a class called Tags.

    I think I will move Tags class in to its own namespace in the next release to avoid any conflicts ("Tags" is a pretty common word..!).

    My apologies :)

    Let me know if you get it working!
     
  16. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    705
    Adding this to buy list, this is so amazing o.o
     
    Last edited: Dec 13, 2014
  17. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    I just learned something new - how to search these things in MonoDevelop (I'm not a programmer . . . or anything computer related really haha - hobby for me). Found the other asset which a little RPG system to learn from. I already had it in another project and don't need it here.

    Thanks for your time and teaching me something today!
     
  18. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    @MIK3K

    No problem! Glad you worked it all out :) Don't forget to drop us a review on the store once you are done evaluating it!

    @Gekigengar

    Thanks for the kind words man! When you get around to purchasing it, We'll be here for feature requests/suggestions/troubleshooting so feel free to get in touch with us. :)
     
  19. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,416
    +1 for own namespace :p
     
  20. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Haha :) I have everything internal namespaced already, I left the Tags static class in the global name space so it was less of a hassle to use, but I think it is decided now - definitely giving it its own namespace in the next update!
     
  21. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    Just FYI - the asset it conflicted with is PhatRobit's "Modular RPG Combat" and you can see in the package contents way down at the bottom under the "tags" folder is "tags.cs."

    I will definitely leave a review when I get a chance to use it. In-place animations and mecanim is making my head hurt really bad.
     
  22. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Thanks for that man!

    I've submitted another update, will post a change list when it is approved and live! Keep an eye out ;)
     
  23. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Would people be interested in PlayMaker support? I haven't had much experience with PlayMaker myself, but I think it would be relatively straightforward to integrate!
     
    LastAi likes this.
  24. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Hey all! New update :) it is live now so update your copy!

    Change Log 1.2.0
    • Moved Tags static class into its own namespace, import/use PigeonCoopToolkit.AllTheTags namespace to access it
    • FindChildrenWithTag method!
    • Light/Dark skin support
    • New section in the docs which covers using AllTheTags with Javascript
     
  25. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Here is an image showing the difference between the light and pro skins! Much easier to read in Light skin now :)

     
  26. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    I think I will start a small FAQ section for AllTheTags! Here is 2 to start, and I'll add these to the first post:

    Tags.FindGameObjectsWithTag(string tag) - how exactly do I use it?

    By default, the FindGameObjectsWithTag returns a ReadOnlyCollection of objects. This is just like a List except that you can't add objects to the list or remove objects from it! The reason it is done this way is because most of the time all you want to do with the result of FindGameObjectsWithTag is iterate over all of the objects and run some code on each object. A ReadOnlyCollection is fine for this task, and it means that we don't have to allocate a new List of objects in memory to hold the result of every FindGameObjectsWithTag operation. Nice and efficient. :)

    You can iterate over a ReadOnlyCollection with a foreach statement, exactly the same as List.

    If ReadOnlyCollection doesn't fit your requirements however, you can still get a normal List out of the results fairly easily so you can do whatever you like with the results!

    Code (CSharp):
    1. List<GameObject> myList = new List<GameObject>( Tags.FindGameObjectsWithTag("MyTag") );
    The documentation mentions that the AllTheTags methods never return null? What do they return if it doesn't find any objects?

    It just returns an empty collection of objects. This way you don't have to do null checks everywhere.

    Code (CSharp):
    1. var taggedObjects = Tags.FindGameObjectsWithTag("MyTag");
    2.  
    3. foreach(var taggedObject in taggedObjects)
    4. ...
    Instead of

    Code (CSharp):
    1. var taggedObjects= Tags.FindGameObjectsWithTag("MyTag");
    2.  
    3. if(taggedObjects!= null)
    4. {
    5.  
    6. foreach(var taggedObject in taggedObjects)
    7. ...
    Do I need to ensure every GameObject has an AllTheTags component before I pass them along to an AllTheTags function?

    No - AllTheTags is very rebust - if an object does not have an AllTheTags component, it will add it for you when you try to check that GameObjects tags. It won't throw any errors at you.

    So you could safetly do Tags.HasTag/etc on any object in your project. Whether they have an AllTheTags component or not doesn't matter!

    Simply add the 'AllTheTags' component to any object that needs one via the inspector, and the rest will handle itself :)

    If an object does not have an AllTheTags component, it is considered to have 'no tags'.
     
    BTStone likes this.
  27. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Small update! There was a small typo in the AddTag function which ment it wasn't working correctly and I feel silly about it. :p You should all update!

    On another note, we've had some really nice reviews on the asset store and lots of positive feedback via email, glad you are all enjoying it. I plan to work on some example scenes soon but I am not sure exactly what I will put together yet. Stay tuned!

    Change Log 1.2.1 Hotfix
    • AddTag wasn't working as intended
     
  28. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    I've been busy lately, and I am preparing another update!

    I am introducing a new object called the TagList. A tag list holds a list of tags (surprise surprise), and you can use it for comparison operations. It is a serializable class, so you can add them to any one of your scripts as a public/protected/private field and edit them in the inspector.

    Bellow is an example - in the example the idea is that our player will receive damage when it comes in contact with any game object tagged as a 'Hazard' or 'Enemy'!

    Here is our player script, note the 'TakeDamageFrom' TagList!

    Code (CSharp):
    1. using PigeonCoopToolkit.AllTheTags;
    2. using PigeonCoopToolkit.AllTheTags.Internal;
    3. using UnityEngine;
    4.  
    5. public class PlayerScript : MonoBehaviour
    6. {
    7.     public AllTheTags.TagList TakeDamageFrom;
    8.     public float Hitpoints;
    9.  
    10.     void OnTriggerEnter(Collider other)
    11.     {
    12.         if (Tags.HasTagFromList(other.gameObject, TakeDamageFrom))
    13.         {
    14.             Hitpoints -= 1;
    15.         }
    16.     }
    17. }
    And this is what it will look like in the inspector, we simply need to enter the tags that we want (In this case, 'Hazard' and 'Enemy') and presto!

     
    Gekigengar likes this.
  29. psilord

    psilord

    Joined:
    Feb 13, 2015
    Posts:
    3
    Hello,

    This is a pretty nice asset. Thanks!

    I have a question though:

    When using Tags.FindGameObjectsWithTag(string tag), it seems that calling it in (a script which is derived from MonoBehavior) the Awake() method, it doesn't find any of my tagged objects. But, it seems to work when called in the Start() method. Is this expected?
     
  30. Pigeon Coop

    Pigeon Coop

    Joined:
    Jan 17, 2014
    Posts:
    186
    Hi -

    Sorry, I should have included that in the docs. Yes, that is expected. The reason is the individual objects must first register them selves with the tag system, and they do this on Awake. You will have to wait for Start!
     
  31. LastAi

    LastAi

    Joined:
    Aug 15, 2013
    Posts:
    8
    Would really love if you added playmaker support.

    Lots of assets on the Asset Store are or have added playmaker support.
    None for muti-tags though.

    Edit: ok I did find one. {https://www.assetstore.unity3d.com/en/#!/content/21475}
    But I really like yours better, organization in your is far superior.
    I really hope you consider adding playmaker support.
    I personally use playmaker because i hate coding, but If i have to i can probly write the action scripts myself. (But i would rather not.)
     
    Last edited: Dec 1, 2015
  32. BigKidIcarus

    BigKidIcarus

    Joined:
    Mar 29, 2018
    Posts:
    1
    I literally just bought this assuming it already worked with Playmaker, so I'm hopeful you can get that working soon.