What's the difference between id and name?

It seems that every object in BabylonJS is required to have a name. And according to the answer in here the name exists solely for the developer, allowing one to look up object by names.

But looks like additionally each object also has an ID. This ID seems to be the same as the name, and there are similar methods to look up object by ID.

var sphere = BABYLON.MeshBuilder.CreateSphere("sphere1", {}, scene);

console.log(sphere.name); // -> sphere1
console.log(sphere.id); // -> sphere1

scene.getMeshByName("sphere1");
scene.getMeshById("sphere1")

It seems like exactly the same feature, just under a different name. But there must be something that’s different about these ID-s? Or not?

1 Like

It is not required. Both name and id are two ways for you to identify your entities. They are not required by the system to work

Usually name is for user display and id is for additional info (depending on user code again)

I recomend always giving useful names to meshes, clones… so you can use scene.getMeshByName(); in case you need to find it in an hay stack.

When cloning a mesh, the id will be similar to name but with ‘. Clone’ or something along thoses lines added to it.

I assume something similar could happen with instances… Not sure on thoses…

If clonning several times the id will become very messy…

1 Like