Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by JamieFristrom · Aug 08, 2013 at 07:06 PM · instantiateclonefindgameobjectwithtag

My player object is getting clone which doesn't show up in inspector

Some of my code finds the player object with

GameObject avatar = GameObject.FindGameObjectWithTag( "Player" );

lately this code has been returning a different player object than the one in the scene. Instead of returning "SwingCharMecAlexis" it's returning "SwingCharMecAlexis (clone)"

Now, as far as I know, I am not instantiating this clone. I don't know where it's coming from, and would like to find out, because that's just weird. I can't even see it in the editor / inspector while the game is running. So what is this strange semi-visible object? Where did it come from?

I searched for every instance of Instantiate in the code, to see if something was somehow accidentally copying SwingCharMecAlexis that shouldn't be, but nothing looks like it could cause this.

Is there some other way a (clone) can be created?

Any advice on how I can track this down?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perchik · Aug 08, 2013 at 07:53 PM 0
Share

When the game is playing, does the clone show up in the editor?

avatar image JamieFristrom · Aug 08, 2013 at 08:53 PM 0
Share

No, it does not show up in the editor while the game is playing.

avatar image CodeAssembler · Aug 08, 2013 at 09:01 PM 0
Share

$$anonymous$$aybe at some point you decided to convert your $$anonymous$$ech$$anonymous$$is in a prefab and deleted the original? So this one is considered a Clone, no matter if its the only one in the scene?

avatar image JamieFristrom · Aug 08, 2013 at 09:04 PM 0
Share

The original's still there, according to the editor.

avatar image WizardGameDev · Mar 24, 2014 at 10:43 PM 0
Share

I ran into this same thing today. What causes this issue as I too had (clone)'s of my main character showing up in my "findGameObjectWithTag" results, but nothing in the hierarchy and I know I'm not making clones of my primary character.

For myself, once I quit out of Unity and got back in then it stopped the strange behavior.

So I'm taking it that the above script is primarily for debugging... You find the object that is giving the problem then you can manually kill it?

Is this a Unity bug with some kind of garbage cleanup? I'm just trying to figure out how clones of my main character got created in the first place.

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by IgorAherne · Aug 08, 2013 at 10:03 PM

before the code put @ExecuteInEditMode if in java. [ExecuteInEditMode] for c#. If it's c#, make sure you write using UnityEditor

right after the GameObject.Find instruction of yours, on a new line, put:

Selection.activeObject = avatar;

If you are writing in c#, here is the code:

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 
 [ExecuteInEditMode]
 public class w : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
     GameObject avatar = GameObject.FindGameObjectWithTag( "Player" );    
     Selection.activeObject = avatar;
         
         Debug.Log (avatar);
     }
 }
 

This is an example of the code, you have to stick it in your code, after the avatar was defined.

As soon as you start moving your object with this script in editor window, it will switch to the object with "Player" tag.

Now, when you see it you can voodoo, slap and be strict with him :D

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JamieFristrom · Aug 08, 2013 at 11:27 PM 1
Share

Gah! Heisenbug! As soon as I started doing this it went away. Now I can't repro it. Which I guess is a good thing. Cool technique though, that goes in the toolbox.

avatar image
1

Answer by Selzier · Oct 23, 2014 at 06:47 PM

I was having this error about every 5 minutes, depending on what I was working on. For example, when working with Animator Controller, I had to restart Unity almost every time I ran the game. It seems to fix the problem adding the following code to one of the main Player's Scripts:

 GameObject[] remaining = GameObject.FindGameObjectsWithTag(Tags.player);
 foreach (GameObject clone in remaining) {
     if(clone.name == "Player_Aleysha(Clone)"){
         GameObject.Destroy(clone);
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Selzier · Nov 23, 2014 at 09:25 PM 0
Share

I think this has to do with using a character from the Scene Hierarchy in the Animation preview window to view animation clips.

avatar image barbe63 · Jan 21, 2015 at 09:33 AM 0
Share

@Selzier Indeed. I can't reproduce it yet but everytime it happens, it adds another clone if i have the preview window opened

avatar image DracoScript · May 10, 2016 at 06:56 PM 0
Share

I'm having this problem with the Survival Shooter tutorial project.

I don't know if it's a bug or what, but I'm solving it by selecting the correct instance of the Player without removing the "clone" ones by using:

// player is a private Transform that will be used to get the player position in order to set the enemys destination in the nav system.

foreach (GameObject i in GameObject.FindGameObjectsWithTag("Player")) { if (i.name == "Player") // The player name is this case is Player, so change if necessary player = i.transform; }

avatar image
0

Answer by heartofgoldfish · Jul 04, 2015 at 07:30 AM

I've noticed this and reported it as a bug: fogbugz.unity3d.com/default.asp?709676_eil9ufq8jqvd5oks

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by meat5000 · May 11, 2016 at 01:34 AM

My player object as generated by NetworkManager always seems to give a clone. Its also easy to forget to remove the prefabbed object you were just tweaking in the hierarchy, giving a clone. Utilise the hierarchy search. A stray flick of the wrist can lose an object to an unsuspecting new parent ;)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to resort to another object if one is not found? 1 Answer

How can I make a game object follow an instantiated game object? 1 Answer

Auto Translate after cloning gameobject using Instantiate() 1 Answer

Instantiating a random dropped consumable item from many cloned objects 1 Answer

Instantiated GameObject's components are disabled 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges