I’ve been messing around with the new 2D tools and the sample demo project and using them as a reference when creating something new from scratch.
Here is the issue: I am trying to use the Camera Follow script that the demo project uses. I made a script file, copied the code in, and linked it to my camera. But it doesn’t seem to work.
I did some digging and placed some Debug.Logs in the code and while the script is running, it seems to have an issue with this piece:
player = GameObject.FindGameObjectWithTag(“Player”).transform;
instead of returning the player object (called hero) it returns an object: hero (Clone). That object doesn’t appear anywhere in my game and I am not instantiating a clone anywhere.
quite odd.
I found this thread with someone having a similar issue:
I added in the code that was suggested and when I run the game the hero (Clone) object is selected in the Inspector, but nearly everything is greyed out. Nothing is selected in the scene and it doesn’t appear in the hierarchy.
It also doesn’t have as many components as the correct hero object does. hero (Clone) only has Transform, Sprite Renderer, and Animator as components, which seems like it might be an early version of the object before I added scripts and colliders, etc. The only thing that is modifiable is sorting layer in the Sprite Renderer component (that component doesn’t exist in the correct hero object).
Anybody have any ideas as to what is going on here? The demo project itself runs as expected.
Well I have been able to get around the issue by creating a new tag for the player and then searching for that in the code.
But I did have the issue happen again, I was only able to fix it by reloading without saving.
I think it may be related to using the animation window, as that is what I was working with when the issue reappeared.
Another note: When it happens, undo will not fix the issue. The hidden cloned object will remain even after undoing to a point that had previously been ok! Still trying to reliably replicate the issue.
I’ve been having the same problem when playing around with the 2D demo project. I came across your post and created a new tag for my player and it fixed the issue. I did notice this after I assigned animations to my player as well. Unfortunately, I’m not sure how to duplicate it either.
Just wanted to add that this is still happening (4.5.3f3), I was messing with animations on my player, and all of a sudden he gets cloned when the game starts, has this been reported as a bug?
This just happened to me in Unity 5.3.0f4 so I’m assuming they still have not fixed the bug. I have Quit and restarted Unity several times and each time I start making changes to the animator, the next thing I know my FindGameObjectWithTag Player tag is no longer recognized returning a null reference. When I debug.log that gameobject upon startup it says it’s a clone.
Using 5.3.1f1 - Having the same problem. Seemingly out of the blue, FindGameObjectWithTag is finding a clone which doesn’t exist in the hierarchy. Deleted my player out of the scene, and it’s still being found. I created a new custom Tag “player”, which is still being found as a clone. Bizarre.
I am having the same issue with Unity 5.3.4f1…
Everything works fine for a while, then all of a sudden, “invisible” clones start appearing in GameObject.FindGameObjectsWithTag() results and make programming impossible.
So far the only solution is to restart Unity, which is a pain. And the clones keep returning after a while anyway.
Just hit the same issue. While I was undocking/watching Animator window my game blew-up on nullRefs and via debug found the player(Clone) symptom. Start and stop of Unity fixed it.