Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Why am i getting "Tag not defined" on this code

Discussion in 'Scripting' started by kalle87, Apr 5, 2016.

  1. kalle87

    kalle87

    Joined:
    Mar 3, 2014
    Posts:
    53
    I cant figure out why im getting "Tag not defined" exception on my gameObject.tag = thisID.ToString(); from what ive read this should be the right way to apply a tag to an object manually?

    Code (CSharp):
    1.  
    2.     void Start()
    3.     {
    4.         GameObject aScript = GameObject.Find("DotSpawner");
    5.         scriptSpawnDot myDotSpawnClass = aScript.GetComponent<scriptSpawnDot>();
    6.  
    7.         thisID = myDotSpawnClass.DotID;
    8.         myDotSpawnClass.DotID += 1;
    9.  
    10.         Destroy(gameObject, 3);
    11.  
    12.         gameObject.tag = thisID.ToString(); /// This Line
    13.  
    14.         startLineRenderer();
    15.  
    16.     }
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    914
  3. DanHedges

    DanHedges

    Joined:
    Jan 21, 2016
    Posts:
    77
  4. kalle87

    kalle87

    Joined:
    Mar 3, 2014
    Posts:
    53
    God dammit this screws up my whole code then :(
     
  5. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    914
    Why don't you just have a class attached to them gameObject's which you use GetComponent on, and give that a string variable called tag? It's a simple workaround :).
     
  6. DanHedges

    DanHedges

    Joined:
    Jan 21, 2016
    Posts:
    77
    @Nigey just so I can understand for my own reference, that would make the code look something like...

    Code (CSharp):
    1. gameObject.myObject.tag = this.id.ToString();
    Is that what you had in mind?

    (obviously not called myObject in real life :) )
     
  7. kalle87

    kalle87

    Joined:
    Mar 3, 2014
    Posts:
    53
    i got it to work, instead of setting the Tag of the gameobject i simply changed the name of it instead and used Find to find it by name :D Onwards to next problem!


    99 little bugs in the code
    99 little bugs in the code
    Take one down, patch it around
    117 little bugs in the code..... Sigh
     
  8. DigitalProgramer

    DigitalProgramer

    Joined:
    Mar 19, 2018
    Posts:
    2
    I had that. just create another tag attach to the object and then put in the code.