- Home /
GameObject.FindWithTag throws an exception since updating to Unity 5.6, but only in WebGL export, not in Editor
I updated my project to Unity 5.6.0f3 last week, without changing anything else about the project.
In some scenes, I search for a GameObject by tag when the scene is loaded. Ever since updating to 5.6, this throws an exception once exported to WebGL. It works as intended in the editor, however.
I'm currently catching the exception and looping and waiting until I find the GameObject, but it never finds it: (Sorry for the hideous code, I added a lot of logs to see where it gets stuck in the build)
GameObject glwGO;
GameLogicWorld glW;
yield return new WaitForSeconds(0.5f);
while (glW == null) {
Debug.Log("A: glw is null, looping to try and find it");
try {
glwGO = GameObject.FindWithTag ("GameLogic");
Debug.Log("B: tried finding glwGO, found: " + glwGO.name);
glW = glwGO.GetComponent<GameLogicWorld> ();
Debug.Log("D: tried finding glW, found: " + glW.name);
}
catch {
Debug.Log("E: Caught exception");
}
Debug.Log("F: Waiting 0.2s");
yield return new WaitForSeconds(0.2f);
}
In the editor, all of this works. It takes a few loops to find the GameLogicWorld script, but it finds the object and all components on it.
(The reason why it takes several loops is that I call the Coroutine already before the scene is fully loaded)
In the build however, I never even get the Debug Log "B", an exception is thrown at GameObject.FindWithTag, and then the loop goes on until forever, never finding the object, always throwing exceptions.
I know that issues with FindWithTag can arise from the game objects simply not being there, but since the GameObject clearly exists in my scene when I test in the editor, I'm confused.
Did anything change about the GameObject.FindWithTag() call in Unity 5.6? I could not find anything about this.
Does the FindWithTag() call throwing an exception definitely mean that the object I'm searching for doesn't exist? Since it exists in the editor, what can I do to find out what happens to the GameObject?
Answer by Schubkraft · Apr 10, 2017 at 08:31 AM
Afaik nothing changed, please file a bug report as explained under https://unity3d.com/unity/qa/bug-reporting
I tested more in depth and in empty projects and other scenes and there the FindWithTag call works in both editor and build. Should I still file a report on the issue of this exception being thrown in the build but not the editor?
Yes if you can attach a project that reproduces the issue.
I've been able to recreate the issue in an otherwise empty project and have filed a bug report. I will edit my original post in case I get any news. Thank you.
Your answer
Follow this Question
Related Questions
when build to webGL 0 Answers
FindWithTag returns NullReferenceException 0 Answers
exception thrown: RuntimeError: index out of bounds 1 Answer
WebGl build throw numbers (maybe assembly pointers) 0 Answers