Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player(Clone) being instantiated?

Discussion in 'Scripting' started by AnthonySturdy, Jun 6, 2016.

  1. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    Hi, I'm getting this weird bug today with Unity, where my enemies are looking towards an object called Player(Clone) at 0,0,0. When I check the 0,0,0 Coord, there's nothing there and there's nothing in the hierarchy.

    The code to find the player is this

    Code (csharp):
    1.  
    2. void Start () {
    3.         target = GameObject.FindGameObjectWithTag("Player");
    4. }
    5.  
    and under that I have
    Code (csharp):
    1.  
    2. Debug.Log(target.name + " " + target.transform.position.ToString());
    3.  
    This prints "Player(Clone) (0.0, 0.0, 0.0)"

    I restarted Unity and it fixed it, but then it came back, so is this a bug with Unity? I'm on version 5.3.4f1

    Cheers, Anthony.

    Edit: I have a feeling the bug is to do with the animation system, and I just noticed there is a newer version of Unity, this might fix it.

    Edit 2: Found this on the Unity 5.3.5 patch notes
    • Animation: Fixed crash when GameObject with Animator is instantiated in StateMachineEnter/Exit. (770045)
    Which looks promising.

    Edit 3: Didn't fix it, but I'm pretty sure it has something to do with the animation system, because the bug only happens when I change something to do with my Players' animation.

    Edit 4: Seems like others are having this problem, couldn't find anything about it yesterday but when being more specific with the search I managed to find things like this: http://answers.unity3d.com/questions/693302/unity-creating-invisible-clone-c.html
    Same problem as me.
     
    Last edited: Jun 7, 2016
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    That sohnds like the start of a horror movie ("the prefab noone could see" anyone?)
    That probably has nothing to do with it, because thats a crash. Because it got fixed for a min after restart, this coukd be a bug, that either noone noticed, or it didnt get fixed
     
    AnthonySturdy likes this.
  3. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    Yeah, it didn't fix it.
    Although I do think it's to do with the animation system because it only happens after I change something to do with my Players animation. If I restart Unity and do other things it's fine.
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Then you know exactly, what's next, create a reproduction project, and submit the bug
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    there is a difference between the transform and the visible mesh (assuming there is one), the transform could quite feasibly be at the origin but the mesh could be moved/displaced anywhere thanks for the animation you're using...
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,181
    Check if it's in the scene at all: search for the name "Player" in the hierarchy search bar (top of hierarchy). It might be a child of some other transform.

    If it's not in the hierarchy, it might be hidden. Try:

    Code (csharp):
    1. Debug.Log(target.name + " " + target.transform.position + " " + target.hideFlags);
     
  7. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    Apparently it's quite a well known bug in Unity, I got around it by excluding the target if it contains "(Clone)"