FindWithTag object is referenced as "Preview Scene"

Hey,

Bumped into an issue I’ve never seen before. As I’m using the line gemRaysObj = GameObject.FindWithTag("GemRays");the script finds the object, but adds in parentheses “(Preview Scene)” after the name. If I click on the supposed referenced file in the inspector, it doesn’t appear in the scene hierarchy. Any thoughts on what might be going on?

Cheers

I’ve also been running in to this. Restarting Unity definitely helped but I’d really like to know what’s causing it as packing arrays with gameobjects for later reference, based on the array’s length is something I do all the time and this breaks the array length when finding all gameobjects with a tag. It seems as though gameobjects are not being fully destroyed in the editor when entering and exiting play mode.

Anyone any ideas?

Hi, @victorknai,

First of all, using GameObject.FindWithTag("ExampleGameObject"); is something I and most people don’t use. (it may seem simple but doesn’t seem to work now.)

What’s recommended is to use public GameObject ExampleGameObject;.

And then to call a function on the gameobject use ExampleGameObject.MyFunctionGoesHere;

I would suggest parenting if you’re working with multiple gameobjects and define the parent in the inspector to be called with your function.

@victorknai,

I had the same issue and some of my scripts where not working as expected at the same time. I restarted Unity and the preview scene was gone and my scripts started working again. Try restarting Unity.

Hope this helps.

using Unity 2017.1.0f3

i had the same problem…just restart unity…hopefully it will work…it is bug in unity !

Just delete your scene from build setting and add again. then this problem is remove. its not any bug in unity