I have a script that fetches a transform using GameObject.FindWithTag("Tag").GetComponent<Transform>();
. This has worked fine for a long time, but now it retrieves a transform from a preview scene(whatever that is). How do I prevent it from looking at preview scene?
2 Answers
Apparently it's a bug, to make that Preview Scene go away you need to close and restart Unity.
For some users though it's not even working that close/restart trick.
I had just ran into this bug really recently, and when closing/restarting Unity doesn't work for me, I do these following things (assuming Windows, and with Unity closed):
- Open 'Run...' and type in "%APPDATA%" (without the quotes)
- this will open you into the Roaming folder.
- delete the Unity folder within
- Navigate up one folder, and you'll see Local, and LocalLow, along with Roaming.
- Enter each of the folders, and delete Unity from within them.
Afterwards, re-open Unity and your 'ghost tag gameObjects' should be gone. I plan on submitting a bug report to Unity, and referencing this post.
FindWithTag
method will return the first object with that tag found in the hierarchy. \$\endgroup\$FindWithTag
. \$\endgroup\$