Moving imported glb model with animation

Can you update the repo with the new code? Thanks.

Never mind, I got your previous repo working. It looks like this is an issue with how you are capturing the avatarMesh value. On the very first launch, when handlePointerInput is assigned, avatarMesh has not been assigned yet, and thus, the value this lambda captured is undefined. Once the mesh is actually loaded, setAvatarMesh will be called, but it’s too late because the avatarMesh has already been captured. If you then subsequently refresh the page (with fast refresh), assigning handlePointerInput will now capture the previous avatarMesh value. But this object has already been disposed because the scene has been disposed. I tested this by adding a global variable instead of using React Native’s useState function and then it worked perfectly.

EDIT: This seems to be a React usage issue and no longer a Babylon question.

1 Like

it’s called a “stale closure” if you want to lookup different solutions. I would suggest useRef instead. Then you can just check the current prop. Note that it won’t cause a React render (like useState), but that looks OK from your snippet.

1 Like

yes, it looks like it. Thank you

1 Like