Set tag doesnt work with certain objects

Im creating a small infinite runner game and i instantiate cubes and gears as a ground. My problem is, that i cant assign tag to gears.

I use this command

klon.tag = "Kolo";

It doesnt work and the tag is always untagged… But when i try to assign this same tag to cubes it works fine and every each of them have it. I really dont understand why ? Maybe because cubes are default objects from unity and gears are imported models ? But it still doesnt make sense for me.

I would be glad for any help. Meanwhile ill create temporary solution, to create different tag for cubes and then use if to get to the gears, but it is not great solution :confused:

I don’t see any problem with that line of code as long as:

  • Your tag “Kolo” is actually defined in the tag manager. You can not use any tag that is not defined in the tag manager.
  • the variable “klon” does reference the correct object.

If the tag is not defined you should actually get a warning / error. To make sure you actually reference the correct object you can use a Debug.Log statement like this right next to the line you posted.

Debug.Log("klon object: " +, klon);

Note the second parameter. It gives the log entry a context object. When you single click the debug message in the console Unity will “ping” the context object in the hierarchy or project panel. Make sure you actually reference the correct object.