1
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ What is this preview scene that you're talking about? Can you provide some context? Consider that the FindWithTag method will return the first object with that tag found in the hierarchy. \$\endgroup\$ – Galandil Mar 21 '18 at 12:55
  • \$\begingroup\$ I have no idea what preview scene is. When I make the variable public, it shows where the transform has been retrieved from "SpawnPoint(transform) (Preview Scene)". Double clicking on it selects the item but its contents in the inspector are all greyed out and it does not focus on the game object in the scene view. \$\endgroup\$ – Aeiou Mar 21 '18 at 12:59
  • 1
    \$\begingroup\$ I've found this thread: answers.unity.com/questions/1381552/… which describes the same bug you're talking about. Try restarting Unity as suggested there, if it doesn't work, I guess atm you need to change how you get the reference by not using FindWithTag. \$\endgroup\$ – Galandil Mar 21 '18 at 13:02
  • \$\begingroup\$ It worked. Thanks for your time. I'll accept your answer if you'll take the time to submit it. Or maybe I should delete the question? \$\endgroup\$ – Aeiou Mar 21 '18 at 13:07
  • \$\begingroup\$ Sure, I'll write it. \$\endgroup\$ – Galandil Mar 21 '18 at 13:12
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.