How to add/subtract child boxes to/from parent mesh which attached to a gizmo when mesh resized/scaled?

Hello everyone, this is my first question in the community.

I have a plane mesh and I attached a gizmo to it. I wanted to add boxes as child of the mesh with fixed size into this plane as much as they fit and I did this.

Now, I want to add/subtract child boxes to/from mesh when mesh resized/scaled. For example, if I increase the size of plane, then if there is available space for new box then add it as additional to existing ones. On the other hand, if I shrink the size then if there is no available space for existing box, dispose the excess one(s). Otherwise, do not nothing.

While doing this, I want to see the adding or subtraction of boxes. The boxes’ size and position must remain same.

Is it possible to do this? If yes, how to do that?
Here is my playground:


cc @Cedric

Since you don’t want the child meshes’ size and position to change with the parent, it is best to unparent them. Then, every time the scale of the plane changes, you’ll have to check all the existing boxes and see if they still fit on the bounding box of the plane, and if not, remove them one by one. Or if they all fit, try to create new boxes and see if they fit.

1 Like

Thanks for quick answer.

Yes, this works but actually I am working in a different project and this playground is just a small representation of my actual problem. In the project, I need to use parent-child relation so I wondered how to do what I want without get rid of parent-child relation.

Is there any way other than unparenting?

You could apply the inverse scale of the parent on the child, but I’m curious why do you need a parent child relationship since it’s main purpose is to have the parent transform affect the child?

I would try to unparent when starting to drag the gizmo and reparent when dragging is over.
It think it’s possible to do it with parent inverse but it might be a bit more difficult to apply the matrix calculation at the right moment in rendering/updating flow.