Create Clone from an Array

Hello everyone,

There are two issues in the PG below that I am currently unable to solve.
https://www.babylonjs-playground.com/#ZQLA5C#6

  1. For each clone (“B”), create a random parented cube above it from arrayH (which holds 3 different meshes). Here’s an example where this almost works–the cube is random (red, green, or blue), but every yellow box clone has the same random cube: https://www.babylonjs-playground.com/#ZQLA5C#4. The goal is for every clone to have a different random red, blue, or green cube.

  2. This might not be possible, but I’m hoping that each clone will respond differently based on which cube it gets. For instance, if a clone is the parent of a “redCube,” then it will start rotating. Or, if it gets a “blueCube,” then the clone will start moving along the x axis.

Hi Anderson,

Here is a playground as you describe, in the loop it creates a new instance of one of the original three cubes, and sets the parent to cloneB, then it adds on render code:

https://www.babylonjs-playground.com/#ZQLA5C#8

Hello @Gijs, and thanks for helping with this, I really appreciate it! :smiley: :+1:

1 Like