UnityException: GameObject has undefined tag! Xcode console message

I get this error when I run my game made using Unity iPhone version 1.7 on my iPod Touch through Xcode's debugger. The exact error message is:

UnityException: GameObject has undefined tag! items.OnTriggerEnter (UnityEngine.Collider other)

(Filename: Line: -1)

It gets spammed a bunch of times in console and as far as I can tell I have all of the tags defined in the Unity Tag Manager. The error does not appear when run on my desktop, only on the iPod. Here is the bit of code, items.OnTriggerEnter:

function OnTriggerEnter (other : Collider){

if(other.tag=="playerBody" || other.tag=="playerHead" || other.tag=="Player" || other.tag=="playerFeet")
{
    ObjectManager.getInstance().ReturnGem(gameObject);
    Collide();
}

}

How do I get rid of this error?

This might be the answer or it might not however firstly, Doireth’s reply led me to the solution of my problem.

I had just moved my project from Unity 5 beta to Unity 5 normal release.
All the tags were in the tag list and all the objects had tags. In editor mode I had no problems with my game however when I used build mode with debugger, I found that I was getting some null references so I investigated and the final error came down to the references not being made because the tags were undefined. This made no sense as all my objects had tags and the tag list was full.

So I OPENED the tag options and clicked ‘add tag’ to find that when I did this, there was not even one tag in the list.
The port from 5 beta to normal 5 seems to have wiped out my tag list.

I re-entered the tag values and the problem is solved.

Thankyou Doireth as your post helped me solve my problem.

When I used:

other.tag == exampleA

I only got a “undefined tag error”
however when I used:

other.gameObject.CompareTag(“exampleA”)

The result I got told me that:
“exampleA tag is not defined”
So I went into the tag list to RE-define it and saw that there was actually nothing in the list even though selecting from the list normally showed the list contained tags. Editing the tag list revealed that none of those tags actually existed.

I know this is a old question but for posterity’s sake I had the same problem and found that:

other.gameObject.CompareTag("Whatever");

Was a much more stable solution.

For me the problem wasn’t at all related to comparing the string. The problem was that I had added old tags and then removed them and in the hierarchy they appeared before the tags that I was using. I think that Unity was confused or threw an exception during the build but NOT during development. The solution was simple: get rid of the removed tags and this is simply by restarting Unity.

i had the same exact problem and what i found out is that i had a tag that i deleted but it stayed as “undefined” in unity so when i made the build it became confused as what that tag is
the solution was as simple as to just close the unity and reopen it and then rebuild again

Just ran into the same problem. This seems to have worked:

	else if( Other.gameObject.tag == "Untagged" )
	{
		// Debug.Log("Hit an object with an undefined tag");
	}

I was seeing the same error message when running on Android, but not within the editor. The same logic error was occurring on iOS, but I haven’t checked the logs to see if this was the exact error message.

This particular project was upgraded from Unity 4 to Unity 5.6.1f1. What I found is that in Project Settings | Tags and Layers there were a few tags marked as “Removed”, and a message from Unity stating that they would actually be removed the next time the project was loaded. Unfortunately, reloading the project would never remove them.

My hunch was that Unity was in a state where it thought the tags were up to date, and that there was nothing to do to them at project load.

The answer was to add a temp Layer, save the project, then reload the project. I restarted Unity just to be safe. The “Removed” tags were then actually removed, and everything is now working properly on Android builds. I’ll test iOS as well, but I would bet money it’s fixed as well.

My assumption is that making a change (adding a layer) marked a dirty flag internally and Unity’s cleanup logic at project load now saw that there was a change to the Tags and Layers and did it’s normal processing. The tags probably got screwed up when upgrading the project from Unity 4 to Unity 5. That I don’t know. The tags look fine in Unity 4.

Afterwards, I did of course remove the temp layer.

Just wanted to comment here in case anyone had the specific problem I had in relation to this, that I solved using the method mentioned by @omarwaleed and @FlameHaze-Yuki

I had a Character controller landing on a moving platform, and was changing the parent to the platform in order to have the player move with the platform. This was done using a Trigger box collider that I tagged “platform” after a couple of typos and removed tags.

This worked great in the editor, but when I built to the android device the player would just slide off like the event OnTriggerEnter was not happening. I also tried OnTriggerStay, to no avail. I also tried searching Google for “OnTriggerEvent not firing on Android” and “Parenting CharacterController.”

It was only after opening Android Monitor in Android Studio and seeing the error “UnityException: GameObject has undefined tag!” pop up, that I found this thread and solved by restarting Unity. Definitely going to be my go to first attempt at any future problem solving!