Programmatically create parent around all children of object

Let’s say I have an entity called world. world has lots of children: lights, models, etc. I’d like to programmatically create a sub-world entity that is a child to world but a parent to all of world's children. (It’s essentially the same as if I created a parent for world, except in this case I want world to remain the top in the hierarchy.)

Is there any quick an easy way of doing that?

Thanks!

Pete

Nothing quick but it’s only a few lines of code.

(untested but similar to this)

var subWorldEntity = new pc.Entity();
var worldEntity = this.app.findByName('world');
var worldChildren = worldEntity.children;
for (var i = 0; i < worldChildren.length; ++i) {
    worldChildren[i].reparent(subWorldEntity);
}
subWorldEntity.reparent(worldEntity);
1 Like

Awesome, super helpful! Thanks a ton.