Unable to disable the VR laser pointer and controller models

(posting for a friend)

I’m trying to create a VR game, and so far everything has been going smoothly. However, no matter what I try, I am unable to disable the VR laser pointer and controller models.

Here is the part that I’m having issues with (I omitted the variable declarations and whatnot as those aren’t relevant):

if VRService.VREnabled then
    task.wait(.2)
    StarterGUI:SetCore("VRLaserPointerMode", 0)
    StarterGUI:SetCore("VREnableControllerModels", false)
    
    VRService:RecenterUserHeadCFrame()
    Camera.HeadScale = HeadScale
    
    VRService.UserCFrameChanged:Connect(function()
        
        local RightHandCFrame = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
        local LeftHandCFrame = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
        local HeadCFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
        
        local RightHandCorrectedCFrame = CFrame.new(Camera.CFrame.Position) * CFrame.new((RightHandCFrame.p-HeadCFrame.Position)*HeadScale) * CFrame.fromEulerAnglesXYZ(RightHandCFrame:ToEulerAnglesXYZ())
        local LeftHandCorrectedCFrame = CFrame.new(Camera.CFrame.Position) * CFrame.new((LeftHandCFrame.p-HeadCFrame.Position)*HeadScale) * CFrame.fromEulerAnglesXYZ(LeftHandCFrame:ToEulerAnglesXYZ())
        local HeadCorrectedCFrame = Camera.CFrame
        
        RightHand.CFrame = RightHandCorrectedCFrame
        LeftHand.CFrame = LeftHandCorrectedCFrame
        Head.CFrame = HeadCorrectedCFrame
        
        ContextActionService:BindAction(ACTION_GRAB_R, handleAction, true, Enum.KeyCode.ButtonR1)
        ContextActionService:BindAction(ACTION_GRAB_L, handleAction, true, Enum.KeyCode.ButtonL1)
        
    end)
    
    RunService.RenderStepped:Connect(function()
        Camera.HeadLocked = false
        Camera.CameraType = Enum.CameraType.Scriptable
        
        local HeadCFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
        
        Camera.CFrame = CFrame.new(0, 5, 0) * CFrame.new(HeadCFrame.Position) * CFrame.Angles(HeadCFrame:ToEulerAnglesXYZ())
    end)
end

As you can see, at the top of my script, I attempt to do so with

    task.wait(.2)
    StarterGUI:SetCore("VRLaserPointerMode", 0)
    StarterGUI:SetCore("VREnableControllerModels", false)

The task.wait(.2) was an attempt at waiting until i was able to set the gui core, but no matter how long i paused it for nothing worked.

I have also tried Player.CharacterAdded:Wait() as suggested by others, but this merely prevented my character from loading.

Any help?

3 Likes

In Nexus VR Character Model, one of its main scripts tries to disable the VR controller models when it’s initializing other parts of the system. It wraps the SetCore call in a pcall and tries up to 600 times (apparently) to hide them.

I noticed the controllers today, so I wrapped its code in a while loop and set it to try hiding the controllers every 30 seconds here.

task.spawn(function()
		while true do
			for i = 1, 600 do
				local Worked = pcall(function()
					StarterGui:SetCore("VREnableControllerModels", false)
					DefaultCursorService:SetCursorState("Detect")
				end)
				if Worked then break end
				task.wait(0.1)
			end
			
			task.wait(30)
		end
	end)

This iffy solution worked for me; Even if the controllers reappear (by pressing the Quest/Oculus button then returning to the game), they’re hidden within 30 seconds. I’m not sure how resource-intensive this would be if it ran every second, though.

1 Like

This is because of a long-standing technical limitation where the CoreScripts may not have registered their SetCore before your code tries to use it. Since my code can start as soon as a player loads, either I’ve found this was needed or I was playing it safe. Don’t remember which; the decision was made in 2018.

Edit: It also protects from the SetCore option being removed, which can and has happened.