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
getting the same thing all of a sudden with GameObject.Find did you ever find the solution?
Answer by mephistonight · Nov 25, 2017 at 07:03 AM
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?
Answer by ALG2132 · Jul 30, 2017 at 01:38 PM
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.
Answer by MrEdens · Sep 06, 2017 at 04:34 PM
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
restarting it is no longer working for me x// idk what to do, have to drag the object manually for testing, its not a major pain but just shouldn't be happening anyways >.< any one figure this out? using 2017.3.03 and no longer fixes on restart
I ran into the same problem too. So annoying. Have you tried to delete your entire Library folder and let Unity recompile everything? (Or move it somewhere else if you want to be safe)
Sometimes I find that works for me, to fix shader glitches.
Answer by fahadshafique · Mar 13, 2019 at 12:43 PM
i had the same problem....just restart unity...hopefully it will work...it is bug in unity !
Answer by Mamoon178 · Apr 17, 2019 at 08:00 AM
Just delete your scene from build setting and add again. then this problem is remove. its not any bug in unity
Your answer
Follow this Question
Related Questions
Trying to restrict movement to bounds of screen using MathF.Clamp() 2 Answers
help! i am a newbie here and i got a problem in scripting 0 Answers
Why Collider2D size Y changes affects child object position 0 Answers
Why is my cube not following the other the way i want ? 1 Answer
How to Undo a lot of created objects at once? [Solved] 1 Answer