FindWithTag returning a game object from "Preview Scene". What is that and why is it not detecting from the active scene?

by Aeiou   Last Updated April 16, 2018 06:13 AM

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?

Tags : unity c#

Answers 2

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.

March 21, 2018 13:12 PM

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):

  1. Open 'Run...' and type in "%APPDATA%" (without the quotes)
    • this will open you into the Roaming folder.
    • delete the Unity folder within
  2. 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.

April 16, 2018 05:58 AM

Related Questions

How to animate objects in Unity 3D

Updated July 12, 2015 13:05 PM