Counting up meshes by ID or name?

Hi,

I’m creating a checkers game and want to keep track of how many pieces each player has. Currently, I track which pieces belong to which player by setting the first number of the mesh name to their respective number (player 1 has 1 before the piece name and vice versa w/ player 2).

I can check if a piece belongs to a certain player with: piece.name[0] === (player number)

Is there a way to look through the scene and find all meshes with the name I am looking for?

Playground: Babylon.js Playground

Thank you!

You can use scene.getMeshByName(‘meshName’)
or use filter like
scene.meshes.filter((m) => m.name === ‘meshName’ )

3 Likes