How to use setParent on a light?

I see https://forum.babylonjs.com/t/camera-setparent-really-needed/52315 works because the camera has rotation. But some lights don’t have rotation, how can I take a light and change its parent so that it moves along with an object, but remains in the same world position and rotation?

maybe there’s some trick I can do with computeWorldMatrix and matrix.decomposeToTransformNode?

Hey there!

You can set your light parent to any object and if the light is a point light it will inherit the position only

If the light is directional, then it will inherit the rotation

but is there a way to set the parent without changing the position or rotation, like setParent would?

Maybe copy the relevant code on setParent. Or maybe set the parent to a TransformNode, then use the TransformNode setParent where needed. Maybe use this:

light.getWorldMatrix().decomposeToTransformNode(transformNode);
light.parent = transformNode;

This is a great answer!