Updating the camera’s CFrame to a new value inside a ‘MouseButton1Click’ listener, causes multiple clicks to be detected. Often even causing the following error:
Maximum event re-entrancy depth exceeded for GuiButton.MouseButton1Click
Expected behavior: the click event handler shouldn’t recursively be called. It should only be called once.
The following studio file replicates the issue. It sets the camera to a different offset inside a ‘MouseButton1Click’ listener function.
VR_button_click_bug.rbxl (56.6 KB)
I understand the minimal example might be a bit far-fetched (not occuring in practice), but it does replicate a bug we have with our character selection menu. In our game we want to update the camera whenever a new character has been selected (make the character fit on screen). This is done in a click listener, causing the bug to occur.
Used VR device: quest 2; occured both when connected to pc, and standalone with the beta app.
Band-aid fix: adding a task.wait(0.1) in the click listener before updating the camera’s cframe.
Suspected cause: the UI shifts when the camera’s CFrame is updated. This probably does a recalculation of clicks?