- Home /
Game works in editor; not builds; "GameObject has undefined tag"
I have been working on a chess game on Unity 5. It works correctly when testing, but after I build to web or exe, and run the game, every time I click a piece, the console spits out "UnityException: GameObject has undefined tag!"
But I checked, all the pieces are tagged, and this is not an error that ever occurs when playing in development mode?
Anyone have any ideas on how to narrow down what's causing this/how to fix? I'm very new to unity (this is only my second project) and would love to get this working.
Answer by Able101 · Jul 06, 2015 at 04:14 PM
I had the same problem and the solution by "Shinugami" solved it: http://answers.unity3d.com/questions/39557/unityexception-gameobject-has-undefined-tag-xcode.html
For those looking at this question after the fact, the linked solution basically says to check the tags in Project Settings to make sure they are actually there. Upgrading from Unity 4 or Unity 5 beta can result in loss of the tags in settings.
Answer by Moath-Qwaqneh · Mar 07, 2017 at 11:04 AM
I faced the same issue but on the Android , I fixed the issue by export the whole of the project and import it to other new project
I had a similar issue on my android build. FindWithTag was working perfectly well when running in the editor but returning null when running on Android Build and Run. The project runs fine on Android after exporting the whole project, and importing it into a new project. I would love any insight from anyone why this fixed the issue, and Thanks to @$$anonymous$$oath-Qwaqn
Answer by Radical · Sep 02, 2017 at 09:01 AM
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.
Answer by OtisMiller · Mar 18, 2018 at 04:09 PM
I had a similar problem. It seemed to just be one function in the game that wasn't working.
Turned out I had a bunch of empty scripts in my game on a prefab which was giving console errors. Was something I'd neglected to solve earlier. Don't know how, but that solved it. Hope that helps.
Your answer