After hearing a few days ago that both EnableMouseLockOption
and DevEnableMouseLock
would be deprecated with this release, I took a look at the API Reference to find out what would be superseding those properties, and I have a few questions and concerns I’d like to share.
MouseBehavior
When looking at either of the deprecated properties on the API Reference, it now recommends the following:
However, after going into Studio and running some tests, it’s unclear how it can be used with the :RegisterTouch/ComputerCameraMovementMode()
methods, as those appear to be exclusively used in PlayerScripts --> PlayerModule --> CameraModule LocalScript
for TouchCameraMovement
and ComputerCameraMovement
modes, which are completely separate from Shift Lock.
I tried the same format of PlayerScripts:RegisterComputerCameraMovementMode(EnumHere)
with the various MouseBehavior Enums and kept encountering the “Unable to cast token to token” error.
On top of that, the MouseBehavior Enums
page only mentions that it’s used for the UserInputService.MouseBehavior
property. Fortunately, this can be updated through scripts during runtime, so I was able to test those out and here’s what I’ve learned so far:
Impossible to force disable Shift Lock?
The three possible values for UserInputService.MouseBehavior
include:
Default: The mouse moves freely around the user’s screen.
LockCenter: The mouse is locked, and cannot move from, the center of the user’s screen.
LockCurrentPosition: The mouse is locked, and cannot move from, it’s current position on the user’s screen at the time of locking
For reference, the property is updated to LockCenter
when the player presses shift to lock the mouse. When unlocking the mouse, the property goes back to Default
. An example of when it’s updated to LockCurrentPosition
is when holding right click to adjust where you’re looking in third-person.
For developers that don’t want players to be able to use Shift Lock in their game at all, is it possible to completely disable the feature using the MouseBehavior
property (in a similar way to the simple and effective EnableMouseLockOption
bool) without needing to constantly listen for the property to be updated?
(Here’s what it looks like when EnableMouseLockOption
is set to false)
Furthermore, based on my testing, forcing the MouseBehavior
property to Default
whenever the property reads LockCenter
does not work as expected:
The example in the video used the following code:
local UserInputService = game:GetService("UserInputService")
UserInputService:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
print(UserInputService.MouseBehavior)
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end)
-- I also tried this but that didn't change the results:
UserInputService:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
print(UserInputService.MouseBehavior)
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
task.defer(function()
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end)
end
end)
Edit (May 24th, 2023): Even if this ends up being fixed, how can we be sure that the MouseBehavior
being set to LockCenter
was caused by the player entering Shift Lock mode and not zooming into the first person perspective? Adding additional checks to make sure we don’t accidentally set the MouseBehavior
to Default
while the player is in first person seems unnecessarily complicated in comparison to the existing solution of setting EnableMouseLockOption
to false from the get-go.
Limitations with MouseBehavior.LockCenter
It seems like there are three different scenarios where the MouseBehavior
is set to LockCenter
:
- When a player presses shift to lock the mouse.
- When a player goes into first-person mode.
- When a
LocalScript
updates the property toEnum.MouseBehavior.LockCenter
.
Although forcing the LockCenter
behavior does lock the player’s cursor to the center of the screen, it resembles what happens in first-person mode instead of the player-activated mouse lock, which is not desirable if a developer wants to enable the standard third-person shift lock (but would probably be fine for other use cases).
Here’s a quick example / comparison video:
The example in the video used the following code:
local UserInputService = game:GetService("UserInputService")
workspace.Part.Touched:Connect(function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
-- Optional (for printing out the current value of the property in the Output)
UserInputService:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
print(UserInputService.MouseBehavior)
end)
MouseBehavior.LockCurrentPosition does not retain locked position after opening and closing the escape menu
If MouseBehavior
is forced to be LockCurrentPosition
, the mouse cursor will be glued to wherever it was on the screen, as expected. When opening the escape menu, the mouse is unlocked (which makes sense so players can adjust settings, leave the game, etc.) but upon closing the escape menu, the cursor doesn’t return to its original locked position.
No idea if that’s intentional or not but I figured I would mention it anyway. Here’s an example video again for reference:
And here’s the code that was used in that example:
local UserInputService = game:GetService("UserInputService")
workspace.Part.Touched:Connect(function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end)
Closing Thoughts
I do enjoy the extra control that is provided with the MouseBehavior
property, but currently, I’m disappointed with the following:
-
Unable to completely prevent players from enabling Shift Lock without scripts (not as seamless as setting
EnableMouseLockOption
to false.) -
Cannot enable standard third-person “Shift Lock” mode for players by updating
MouseBehavior
toLockCenter
. Only results in the first-person style of mouse lock.
In summary, it would be nice to have some clarification on the deprecation of EnableMouseLockOption
and DevEnableMouseLock
, as well as to have some insight into the functionality of the MouseBehavior
enums, property, etc.