Getting mesh's rotation throws error


I am currently trying to get the rotation of a mesh but I get the error such as Cannot read property 'rotation' of null. I do the same for a transform node - getTransformNodeByName and that works without any issues. But when I try to achieve the same with a mesh, it causes this problem. What is the solution here?

var currentRotation = { x: 0, y: 0 };
let mesh01 = scene.getMeshByName("Mesh001");
currentRotation.x = mesh01.rotation.x;
currentRotation.y = mesh01.rotation.y;

“Cannot read property “rotation” of null” is usually caused when the mesh being targeted doesn’t exist in the scene. It would be more helpful if you can create a playground of the same. I would suggest you to console and check if that particular mesh exists or not.

1 Like