Parents, who needs em? I do!

I for the life of me can’t get meshes to parent to a transform node when using SceneLoader.LoadMeshes. I have tried using mesh.parent = this.rootNode, mesh.setParent(this.rootNode) this.rootNode.setChildren(mesh) and at this point many other non standard ways.

What am I doing wrong? I want all of the meshes loaded from the file to be parented to a transformnode called “this.rootNode” so I can more easily position / scale. Then ideally the meshes are stored in an array. This is like Babylon 101 :frowning: but I have been beating my head around it and searching for hours trying to figure out what I did wrong.

import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader"; import { TransformNode } from "@babylonjs/core/Meshes/transformNode"; import { Vector3 } from "@babylonjs/core/Maths/math"; import { Mesh } from "@babylonjs/core"

export class aNode {
public rootNode;
public name: string;
public s; // scene
public meshArray;

constructor(mediaPath, public nodeName: string, public fileName: string, s){
    this.name = fileName;
    this.rootNode = new TransformNode("rootNode", s);
    this.rootNode.position = new Vector3(0, 0, 0);
    this.makeMesh(mediaPath, fileName, s);
}

public makeMesh(mediaPath:string, fileName: string, s){
    let meshPath = mediaPath + "models/" + fileName + "/";
    let meshName = fileName + ".gltf"
    var meshRecord = SceneLoader.ImportMesh("", meshPath, meshName, s, function(newMesh) {
        newMesh.forEach(function(mesh){
            mesh.setParent(this.rootNode)
        })
    },
    function(meshProgress){
        //OnProgress
    }, 
    function() {
            // onError
    })
 }

}

Hi. Yes, this is not a very good approach, because maybe your array of meshes inside already have a hierarchy, maybe some already have a parent. And I think this is your case too.
More than that if you’ll console your meshes, or check the hierarchy in inspector you’ll see that your meshes already have a ‘big’ parent called root, you can use this for reposition, rotation,etc. Or if you still want to have your own parent, you can simply parent meshes[0].
Cheers!