Why does clone have a different position and orientation than my default in game object?

I am importing my own 3D mesh (a ply file converted to a .obj and imported to Unity) and using it to render an image in Unity. I have added the object to prefab and I’m accessing it during rendering (Code is attached at the end)

While rendering I’m noticing that there are two objects - Clone and default (which have different orientations, positions, and scale). The Clone seems to have the positions, orientations, scale, etc I’m setting from my script, but the one that is getting rendered is the default one. I can see this when I select the objects and observing the co-ordinate frames. Adding pictures for reference.

Why are there two objects, and how do I get the correct one to render?

As an experiment I tried changing the properties of the default to match the ones of the clone, (so I thought if I match them, the default one which is rendering would come to the pos and orientation that I want), but when I did that the default went completely out of the frame to a different pos altogether, so I am suspecting they are on different coordinate frames altogether)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SceneController : MonoBehaviour
{
    public ImageSynthesis synth;
    public GameObject[] prefabs;
    public int num_Objects = 2;

    public int trainingImages;
    public int valImages;

    public bool grayscale = false;
    public bool save = false;

    private ShapePool pool;

    private int frameCount = 0;

    // Start is called before the first frame update
    void Start()
    {
        pool = ShapePool.Create(prefabs);
    }

    // Update is called once per frame
    void Update()
    {
        if (frameCount < trainingImages + valImages) {

            GenerateRandom();
            Debug.Log($"FrameCount: {frameCount}");
            frameCount++;

            if (save)
            {
                if (frameCount < trainingImages)
                {
                    string filename = $"image_{frameCount.ToString().PadLeft(5, '0')}";
                    synth.Save(filename, 1920, 1080, "captures/train", 2);
                }
                else if (frameCount < trainingImages + valImages)
                {
                    int valFrameCount = frameCount - trainingImages;
                    string filename = $"image_{valFrameCount.ToString().PadLeft(5, '0')}";
                    synth.Save(filename,  1920, 1080, "captures/val", 2);
                }

            }

          
        }
    }

    void GenerateRandom()
    {
        pool.ReclaimAll();
       
                //pick out prefab
                int prefabIndx = Random.Range(0, prefabs.Length);
                GameObject prefab = prefabs[prefabIndx];
               
                //OBJECT 1
                /*
                DATA from Python script
                PSM_1 Orientation in quaternions  WXYZ [ 0.06844   0.458484 -0.60438   0.647945]
                PSM_1 Position in mm [14.620537  3.197186 64.227186
                */

                //Position
                float newX, newY, newZ;
                newX = 14.620537f;
                newY = 3.197186f;
                newZ = 64.227186f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation
               
                float quatX = 0.458484f;
                float quatY = -0.60438f;
                float quatZ = 0.647945f;
                float quatW = 0.06844f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float sx = 1.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color
                /*
                float newR, newG, newB;
                newR = Random.Range(0.0f, 1.0f);
                newG = Random.Range(0.0f, 1.0f);
                newB = Random.Range(0.0f, 1.0f);

                var newColor = new Color(newR, newG, newB);
                newObj.GetComponent<Renderer>().material.color = newColor;
                */
            }
              
        }
            synth.OnSceneChange(grayscale);
        }
    }

A mesh renderer with no mesh filter doesn’t do anything, it’s basically a dummy component on a parent game object. The “default” is the actual mesh that’s being rendered.

Usually the obj file format is used to hold a single mesh, and Unity’s importer is probably setup assuming that setup. However the format does support additional named objects, and it seems whatever method you used to convert your original ply file into an obj did so by putting all of the triangles in an object named “default” inside the obj file instead of leaving it in the root mesh. This is a little silly since AFAIK the ply format does not support multiple objects and is always a single mesh.

The “default” object is however just a child of the main game object and thus will move and scale with the parent. The transform component will show values in it’s parent’s coordinate space. As for why it has been moved off of 0,0,0, rotated, and scaled, I can only guess that you accidentally modified the prefab or otherwise moved the child object after spawning it. The obj format does not support unique pivots per object and all are assumed to be in the same space.

My suggestion would be to move the “default” object out by itself, rename it, and either save it as a new prefab to use.

Thank you for the detailed answer, really appreciate it.

“As for why it has been moved off of 0,0,0, rotated, and scaled, I can only guess that you accidentally modified the prefab or otherwise moved the child object after spawning it.” I don’t really remember doing it, but this was 2 weeks ago, when I literally had zero experience with Unity, and I must have done something silly.

I converted .ply into .obj I guess using an online converter, which probably isn’t the best way to do it. So what I am going to do now, is to convert it using Blender, and try a .fbx instead.

P.S - Tried importing again, but again, somehow the child “default” is twisted by 90 degrees about X-axis of the parent. I ended up separating the child from the parent object and rendering it separately! Worked! Thank you!