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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

MultiTags Released!

Discussion in 'Assets and Asset Store' started by charmandermon, Sep 15, 2014.

  1. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Will this work with Unity 4.3.X ?
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    in 4.6.1: BCE0019: 'HasTag' is not a member of 'UnityEngine.GameObject'.
    though the MultiTags script is on a gameobject, and has local and global tags assigned (?)
     
  3. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    hmm works fine in all my builds...Tested in Unity 4.6.1, 4.6.2, 4.6.3, and 5 beta

    I wonder if the conflict is because of another asset or package in the project? MultiTags doesn't do anything special it should be fine for a good long time.
     
  4. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Hi, is possible a video tutorial? Thx
     
  5. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    How would you go about finding all gameobjects that have more than one tag? Say I want to find all objects that have the tags "Dog" and "Brown"? Thanks!
     
  6. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    Something tells me you like dogs, although I can't put my finger on why. Code: After thinking about it I don't think my framework can do what you ask. Although its a really cool idea. I will warn however against doing that. If you were doing intricate list searching with infinite levels like that it could really slow down your game/project(on Update calls). The code is pretty straight forward to add it on the outside. I would just have a list of object x and do another comparison of those game objects for object y. Does that help?
     
  7. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    Sorry I just saw your message I will absolutely put together a video tutorial asap!
     
  8. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    Yeah, makes sense. Was curious :D

    Cheers.
     
  9. Crivens

    Crivens

    Joined:
    Jul 30, 2012
    Posts:
    34
    Excellent plugin. Totally does what I want.

    One thing that would be really cool, is if the Multitags could have data attached (which can be amended). Easy enough to handle yourself, but would be really convenient if could find all objects with a MultiTag (as you can now), and then with a similar command get values attached to other MultiTags against the same object.

    For example instead of this:-
    Code (CSharp):
    1.         GameObject[] enemies = MultiTags.FindGameObjectsWithMultiTag("Enemy");
    2.         foreach (GameObject enemy in enemies)
    3.         {
    4.             stats enemyStats=enemy.GetComponent<stats>()
    5.             if(!enemyStats.boss)enemyStats.energy--;
    6.         }
    Then this:-
    Code (CSharp):
    1.         GameObject[] enemies = MultiTags.FindGameObjectsWithMultiTag("Enemy");
    2.         foreach (GameObject enemy in enemies)
    3.         {
    4.             if(!enemy.TagData("Boss"))enemy.TagData("Energy")--;
    5.         }
    Something like that anyway. Basically a way of quickly accessing (or attaching) data connected to any object, without mucking around.

    Cheers
     
  10. gibmation

    gibmation

    Joined:
    Dec 1, 2014
    Posts:
    311
    First congratulations for an excellent product!

    I am using playmaker with arraymaker.
    I am using MulitTags to add tags to various objects which are in an array.

    there is a playmaker action with arraymaker which find closest gameobject in the array.

    I would like to customize this action so I can look for object with a multi-tag.

    I am sorry but do not have enough programming knowledge to accomplish this, could you help out with this?
    Thanks in advance.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace HutongGames.PlayMaker.Actions
    4. {
    5.     [ActionCategory("ArrayMaker/ArrayList")]
    6.     [Tooltip("Return the closest GameObject within an arrayList from a transform or position.")]
    7.     public class ArrayListGetClosestGameObject : ArrayListActions
    8.     {
    9.         [ActionSection("Set up")]
    10.        
    11.         [RequiredField]
    12.         [Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
    13.         [CheckForComponent(typeof(PlayMakerArrayListProxy))]
    14.         public FsmOwnerDefault gameObject;
    15.        
    16.         [Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
    17.         public FsmString reference;
    18.        
    19.         [Tooltip("Compare the distance of the items in the list to the position of this gameObject")]
    20.         public FsmGameObject distanceFrom;
    21.        
    22.         [Tooltip("If DistanceFrom declared, use OrDistanceFromVector3 as an offset")]
    23.         public FsmVector3 orDistanceFromVector3;
    24.        
    25.         public bool everyframe;
    26.        
    27.         [ActionSection("Result")]
    28.        
    29.         [UIHint(UIHint.Variable)]
    30.         public FsmGameObject closestGameObject;
    31.        
    32.         [UIHint(UIHint.Variable)]
    33.         public FsmInt closestIndex;
    34.        
    35.        
    36.         public override void Reset()
    37.         {
    38.        
    39.             gameObject = null;
    40.             reference = null;
    41.             distanceFrom = null;
    42.             orDistanceFromVector3 = null;
    43.             closestGameObject = null;
    44.             closestIndex = null;
    45.            
    46.             everyframe = true;
    47.         }
    48.        
    49.        
    50.         public override void OnEnter()
    51.         {
    52.  
    53.             if (! SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
    54.             {
    55.                 Finish();
    56.             }
    57.            
    58.             DoFindClosestGo();
    59.            
    60.             if (!everyframe)
    61.             {
    62.                 Finish();
    63.             }
    64.            
    65.         }
    66.        
    67.         public override void OnUpdate()
    68.         {
    69.             DoFindClosestGo();
    70.         }
    71.        
    72.         void DoFindClosestGo()
    73.         {
    74.            
    75.             if (! isProxyValid())
    76.             {
    77.                 return;
    78.             }
    79.            
    80.             Vector3 root = orDistanceFromVector3.Value;
    81.            
    82.             GameObject _rootGo = distanceFrom.Value;
    83.             if (_rootGo!=null)
    84.             {
    85.                 root += _rootGo.transform.position;
    86.             }
    87.            
    88.             float sqrDist = Mathf.Infinity;
    89.        
    90.             int _index = 0;
    91.             float sqrDistTest;
    92.             foreach(GameObject _go in proxy.arrayList)
    93.             {
    94.                
    95.                 if (_go!=null)
    96.                 {
    97.                     sqrDistTest = (_go.transform.position - root).sqrMagnitude;
    98.                     if (sqrDistTest<= sqrDist)
    99.                     {
    100.                         sqrDist = sqrDistTest;
    101.                         closestGameObject.Value = _go;
    102.                         closestIndex.Value = _index;
    103.                     }
    104.                 }
    105.                 _index++;
    106.             }
    107.  
    108.         }
    109.        
    110.     }
    111. }
     
  11. Thomvdm

    Thomvdm

    Joined:
    Feb 24, 2016
    Posts:
    35
    I'm trying to write a switch based on the tags, that would look like the following:

    Code (CSharp):
    1. private string selectedObjectTag = selectedobject.gameobject.tag;
    2.  
    3.      switch (selectedObjectTag) {
    4.          case "Tag1":
    5.              Debug.log("Tag1");
    6.              break;
    7.            case "Tag2":
    8.              Debug.log("Tag2");
    9.              break;
    10. }
    11.  
    However, selectedObject.gameobject.tag would only check on native Unity tags, not on MultiTag tags. I probably missed it somewhere as I don't believe you don't have a function to check the tag(s) of an object, but how do I do this?
     
  12. gibmation

    gibmation

    Joined:
    Dec 1, 2014
    Posts:
    311
    Forget this, I removed Mulitags and used sqlite instead.
    Regards
    G.

     
  13. gibmation

    gibmation

    Joined:
    Dec 1, 2014
    Posts:
    311
    Hi I saw your post, I hope this is of help to you.

    G.

    //thisisthestandardtagcheck,itwillreturntrueorfalse.
    HasTag(string);

    //AddTagwillFIRSTaddtheMultiTagsComponenttothegameobjectifitdoesnotexist,
    //thenitwilladdthetagthatyoupassthroughasastring.
    AddTag(string);

    //RemoveTagwillchecktoseeiftheMultiTagscomponentexiststhenthelistifthetagexiststhenremovesthetagfromthe list
    RemoveTag(string);


    LOOKUPS
    GameObject go = MultiTags.FindWithMultiTag("ElderBeast");

    GameObject[] gos = MultiTags.FindGameObjectsWithMultiTag("Beast");

    int amount = MultiTags.FindGameObjectsWithMultiTagCount("Beast");
     
  14. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @charmandermon ,

    Just asking whether this Asset is still being developed? Any plans to help with Playmaker FSMs to support new Playmaker Arrays? Also, is it Unity 5.4 compatible?

    Also, an (albeit slower) way to search for a GO or array of GOs or count of GOs by multiple MultiTag strings at once would be neat? If not, how would I code it?
     
    Last edited: Aug 7, 2016
  15. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @charmandermon

    Any chance of help in making a Playmaker collide2d tag action?
     
  16. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @charmandermon ,

    Now Playmaker arrays are fully there, any chance of updating this asset to support them?
     
  17. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    Ya sure, that doesn't sound too complicated. How do you want it to function? - Dustin
     
  18. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    A playmaker array of tags. Searching action for objects with one or more of tags in Playmaker...?
     
  19. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    Hi, I have created an extension for searching objects with specific tags

    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Tags : MultiTags
    6. {
    7.     public static GameObject[] FindGameObjectsWithMultiTag(string[] arrayTags)
    8.     {
    9.         GameObject[] aux = FindGameObjectsWithMultiTag(arrayTags[0]);
    10.         List<GameObject> results = new List<GameObject>();
    11.         bool isObj = true;
    12.         if (aux != null)
    13.         {
    14.             foreach (GameObject obj in aux)
    15.             {
    16.                 isObj = true;
    17.                 foreach (string tag in arrayTags)
    18.                 {
    19.                     if (!obj.HasTag(tag))
    20.                     {
    21.                         isObj = false;
    22.                         break;
    23.                     }
    24.                 }
    25.                 if (isObj)
    26.                 {
    27.                     results.Add(obj);
    28.                 }
    29.             }
    30.         }
    31.         if (results.Count > 0)
    32.         {
    33.             return results.ToArray();
    34.         }
    35.         else
    36.         {
    37.             return null;
    38.         }
    39.     }
    40.  
    41.     public static GameObject[] FindGameObjectsWithMultiTag (string tag1, string tag2)
    42.     {
    43.         return FindGameObjectsWithMultiTag(new string[] { tag1, tag2 });
    44.     }
    45.  
    46.     public static GameObject FindWithMultiTag(string[] arrayTags)
    47.     {
    48.         GameObject[] arrayObjects = FindGameObjectsWithMultiTag(arrayTags);
    49.         if (arrayObjects != null)
    50.         {
    51.             return arrayObjects[0];
    52.         }
    53.         else
    54.         {
    55.             return null;
    56.         }
    57.     }
    58.  
    59.     public static GameObject FindWithMultiTag(string tag1, string tag2)
    60.     {
    61.         return FindWithMultiTag(new string[] { tag1, tag2 });
    62.     }
    63. }
    64.  
    Code (csharp):
    1.  
    2. public static class ExtendTag
    3. {
    4.     public static string[] ReturnTags(this GameObject value)
    5.     {
    6.         MultiTags multiTags = value.GetComponent<MultiTags>();
    7.         if (multiTags)
    8.         {
    9.             List<MT> mts = multiTags.localTagList;
    10.             string[] tags = new string[mts.Count];
    11.  
    12.             for (int i = 0; i < tags.Length; i++)
    13.             {
    14.                 tags[i] = mts[i].Name;
    15.             }
    16.             return tags;
    17.         }
    18.         else
    19.         {
    20.             return new string[] { };
    21.         }
    22.     }
    23.  
    24.     public static string ReturnTag(this GameObject value)
    25.     {
    26.         string[] tags = value.ReturnTags();
    27.         if (tags.Length > 0)
    28.         {
    29.             return tags[0];
    30.         }
    31.         else
    32.         {
    33.             return null;
    34.         }
    35.     }
    36.  
    37.     public static bool HasTags(this GameObject value, string[] tags)
    38.     {
    39.         if (tags != null && tags.Length != 0)
    40.         {
    41.             foreach (string tag in tags)
    42.             {
    43.                 if (!value.HasTag(tag))
    44.                 {
    45.                     return false;
    46.                 }
    47.             }
    48.             return true;
    49.         }
    50.         else
    51.         {
    52.             return false;
    53.         }
    54.     }
    55.  
    56.     public static bool HasTags(this GameObject value, string tag1, string tag2)
    57.     {
    58.         return value.HasTags(new string[] { tag1, tag2 });
    59.     }
    60. }
    61.  
     
    Last edited: Feb 28, 2017
  20. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @Amalfi-Prozen ,

    Thanks for that ... would your method allow me to search for gameobjects which all had 3 specific tags?

    Also, how fast are your 2 methods?
     
  21. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    yer, there is an array of string (any element is a tag)
     
  22. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    Great thanks
     
  23. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    I change the script for refactoring XD
     
  24. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    316
    Does this still work on the last version of Unity 2017? I'm not concerned with 2018 beta, at least not until the upload the new substance plugin
     
  25. CodeMonkey2k

    CodeMonkey2k

    Joined:
    Jul 28, 2018
    Posts:
    1
    I have written a range of additional MultiTag helper functions to extend its capabilities for some game ideas I am working on, and I have written PlayMaker Actions for each new function added to MultiTags as well. Primarily I am doing things like checking ifan item contains multiple assigned MultiTags compared to an input list. Some examples of what I am creating are things like HasTagsCount(tagsToCheck) and HasTags(tagsToCheck) the first returns an int count of the matches found while the second returns a string array of matches. Some other functions allow for the use of wildcard searches as well. Anyways, I am currently struggling with two things and I thought I would turn to the community and the developer for help.

    1) I would like a to make an array of existing global tags in the either the MultiTags class or the MultiTagsHelperMethods class but find myself unable to do so. Either way I would like this list to be accessible to the functions and routines within both classes.
    2) I am running into an issue where I would like to drop multiple prefabs in the scene and then assign the different tags in the inspector. Currently Unity will allow me to assign the tags on each prefab instance in the scene individually, but the moment I hit play to test the scene the instance specific MultiTag values are wiped out and the prefab state (no tags) is used. I can then make tagging changes at run-time and the rest of my scripts and actions work but I would really like to have the ability to set tags on prefabs and on instances as well. Any thoughts?
     
  26. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    When I add the multitags component to a prefab and assign global tags to local tags, the next time I open the prefab, the local tags are empty. Seems it is not storing the local tags.

    Am I doing something wrong?

    Thanks
    Andy
     
    sampenguin likes this.
  27. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    58
    Just observed similar behavior in Unity 2018.3.11, except that when instancing the prefab at run time the tags go missing and there's just one local "Untagged" tag. Guessing this asset hasn't been updated for the current prefab functionality and looks like it's abandoned... probably gonna have to dig into source and fix it ourselves.

    WORKAROUND:
    I just discovered if I adjust the order of another component in the prefab editor after adding tags they stick (although it still generates an "Untagged" tag at runtime in addition to the ones I specify). My guess is the editor scripts aren't flagging a dirty flag appropriately in MultiTags when you assign/unassign a tag, but I don't have time to check right now.

    FIX:
    Found a fix. See post below.
     
    Last edited: Apr 7, 2019
  28. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    sampenguin
    Thanks for pointing this out.
    I think I will not use this asset in my production because it is too risky to work with unsupported software.
     
  29. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    58
    I figured out a fix. Add these two lines inside the "if(GUI.changed)" block at the bottom of MultiTagsInspector.cs.

    EditorUtility.SetDirty(myScript);            EditorSceneManager.MarkSceneDirty(myScript.gameObject.scene);


    I've used this package in multiple shipped games. It is really quite handy for multi tagging. This is the first problem I've encountered with it, and since it's an editor only issue not really much of a risk. YMMV :)
     
  30. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    97
    Hey that is good news. Will have a look at it!

    Thanks for posting this!
     
  31. SkullKing

    SkullKing

    Joined:
    May 31, 2012
    Posts:
    40
    I am using Multitags with playmaker and I think i am doing something Dumb with "HasTag" Action

    In this Action how does the has "Has Tag" Bool funtion? If I put a custom Bool there, will it set to true if the object has the specified Tag, and to False if it does not?

    thank You for Your time