Search Unity

5.6b11 - Phantom Cube object around 0f,0f,0f. Doesn't appear in Hierarchy. Can't Delete it.

Discussion in '5.6 Beta' started by Spanky11, Mar 10, 2017.

  1. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    In my (Vive) game, I use a Physics.Raycast laser pointer to teleport around the scene. Today I noticed that around Vector3(0f,0f,0f) the Raycast was hitting an invisible object that I didn't expect to be there.

    When I print the name of the object, its name is "Cube", but this object does NOT appear anywhere in the Hierarchy. In the code below, I tried renaming this object to "katie" , and the name change prints in the console, but again I don't see any "katie" object in the Hierarchy. I tried to DestroyImmediate it, but in the next frame it's back (with name="Cube").

    Code (CSharp):
    1. if (hitGameObject) {
    2.                 UnityEngine.Debug.Log("hitGameObject=" + hitGameObject.name);
    3.                 if (hitGameObject.name.Equals("Cube")){
    4.                     UnityEngine.Debug.Log("LocalScale=" + hitGameObject.transform.localScale);
    5.                     Renderer rend = hitGameObject.GetComponent<Renderer>();
    6.                     UnityEngine.Debug.Log("rend=" + rend);
    7.                     rend.enabled = true;
    8.                     hitGameObject.name = "katie";
    9.                     UnityEngine.Debug.Log("now hitGameObject=" + hitGameObject.name);
    10.                     UnityEngine.Debug.Break();
    11.                 }
    12.             }
    I checked around to see if I had any code that was creating this object, but didn't fine any. If I was creating it, then it would appear in the Hierarchy. This seems like something Unity added but forgot to remove.
     
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    787
    Couldn't reproduce it in an older version, but I know Unity has quite a few strange hidden objects ghosting around in the scene.

    You can make them all visible when you iterate over all objects and change the hide flags. Maybe you can try that to unlock the object (at least you can see it in the editor then).

    But be careful, you can permanently screw up your scene completely if you change the flags wrong... (as in, you don't have a scene view camera anymore and other stuff). So don't save the scene if you try that :p
     
  3. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    How do you iterate over all the objects? What is the hide flag? Do you mean the active/inactive checkbox in the Inspector? The only way I know to access objects is in the Hierarchy, and this object isn't there. Hopefully someone from Unity can chime in here. In my game, you can scale the world down so that the entire area you are working in (It's a builder game) is the area right around 0f,0f,0f. This object totally gets in the way of everything, so it's super annoying.
     
  4. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,010
    I had a similar issue, where one UI image was visible in the scene and game view, but not in the hierarchy.

    I ended up duplicating that scene, deleting everything in the hierarchy and saving the changes. Then I used a text-editor to check what was left in the scene file. This probably works only if the editor is AssetSerializationMode=Text. I found that phantom UI image fairly quickly in the text-editor.

    I then opened the original scene in a text-editor, searched for what I just assumed to be the UI image and removed it. Having a rough understanding of the Unity text-based scene format is helpful. Make sure to backup your scene before doing any modifications in a text-editor to it, as messing up the scene file is easy.

    That way I was able to get rid of that object
     
  5. ScottF

    ScottF

    Director of Development, Mobile Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    86
    Can you reproduce this in an empty scene? Are you using any Asset Store packages, Unity UI etc? I
     
  6. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    787
    You would have to use code.
    Iterate with transform.Childcount and .getChild(), and the hide flags are just obj.hideFlags, but they are flags, not a normal value so setting them directly (without |= and & =) will cause all sorts of trouble.

    If you are new to programming / don't know what I'm talking about then don't try this.
     
  7. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    I tried setting hideFlags to HideFlags.None, but it still doesn't appear in the Hierarchy. For kicks, I tried adding a HingeJoint to the object, but searching the Hierarchy for "HingeJoint" doesn't show the object.

    I tried creating an empty scene and then copying over all the objects in my Hiarchy, but the phantom Cube remains.


    Code (CSharp):
    1.   GameObject hitGameObject = pointerCollidedWith.collider.transform.gameObject;
    2.             if (hitGameObject) {
    3.                // UnityEngine.Debug.Log("hitGameObject=" + hitGameObject.name);
    4.                 if (hitGameObject.name.Equals("Cube")){
    5.                     hitGameObject.hideFlags = HideFlags.None;
    6.                     UnityEngine.Debug.Log("LocalScale=" + hitGameObject.transform.localScale);
    7.                     hitGameObject.AddComponent<HingeJoint>();
    8.                    // UnityEngine.Debug.Break();
    9.                 }
    10.             }

    Scott, I haven't tried creating an entirely empty project with a new empty scene, but I will try this. Also, I'm using a million billion Asset Store packages. Well, not that many really... but a lot.
     
  8. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    I created an empty scene and just added the SteamVR camera Rig, a terrain, and the SteamVR Toolkit pointer script, and the Raycast is still hitting the Phantom "Cube" object. I tried changing the layer to "Ignore Raycast", but this also didn't work. I tried Peter's suggested, but didn't see any "Cube" object in the text editor. I think this object is being created every frame, only when the project is running. I'm not sure what to try next.
     
  9. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    787
    Have you set the hide flags to none again?
    Hide flags can also be set to "don't save". And then you won't find the cube in the text file.

    Setting it to none will un-hide it and make it so its saved when you save the scene.
    https://docs.unity3d.com/ScriptReference/HideFlags.html
     
  10. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    Will setting it to none make it visible in the Hierarchy? Because it's still not visible there. I checked my 5.6b9 version of my project and the phantom cube isn't there. I really haven't changed must since switching to 5.6b11, so I'm wondering if a dev left something in place accidentally. Unity, this is: "(Case 889740) Phantom Cube at 0,0,0 - 5.6b11"
     
  11. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    787
    Setting hide flags to none should definitely make it visible, yes.
    But if not, that sounds pretty spooky haha, must be some crazy bug they introduced on accident in the new beta.

    Try another thing though, you have a reference to the object, so do .gameObject.AddComponent... and add a mesh filter and mesh renderer through code.
    Maybe there's something visible that way... like it resetting itself when you do something, i don't know...
     
  12. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    The object already has a Mesh Filter "Cube Instance (UnityEngine.Mesh)",
    and a MeshRenderer. I enable the renderer and set the material color to blue.
    Nothing. I try changing the transform.position. No help. crap!

    I guess I'll try creating a brand new project and then write a script to Physics.Raycast to 0,0,0 and see if I keep htting this. I opened a minimal example scene from an asset I had purchased, and saw the same thing there.
     
  13. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,463
    Sometimes colliders can be irregular and cause these issues, for example mesh collider being forced to convex or something.
     
  14. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    hmm, I'm not sure I understand your comment. Are you suggesting that setting the mesh collider for a different object to convex can cause a phantom object to be created?
     
  15. Spanky11

    Spanky11

    Joined:
    Mar 9, 2015
    Posts:
    295
    Ok, as you might have guessed, I caused the phantom cube. In one of my update methods I found the following code:


    Code (CSharp):
    1. GameObject cubeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
    2. Destroy(cubeObject);
    3.  

    It's a large project and I only discovered this by randomly stumbling upon this. Don't ask me why I was creating a Cube object and then immediately destroying it. I must have been trying to test something. I had searched the project for "Cube" in quotes which didn't turn up the above code. Yes, I could have searched for Cube without quotes, but this would return 100+ results.

    I apologize to anyone who may have spent time reading this.
     
    Charles_Beauchemin and LeonhardP like this.