Device Emulator Does Not Update Device Specific Values Until After User Input

I have this code that I use to check what device a user is on, and it properly detects my device when I play my published game, but whenever I am trying to test the game in studio using the device emulator, i noticed that it doesn’t return the correct values until after i send in the first input.

local GS = game:GetService("GuiService")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local Detect = {}

function Detect:GetDevice(MobileSpecific:boolean)
	local Device = nil
	if (GS:IsTenFootInterface()) then
		Device = "Console"
	elseif (UIS.TouchEnabled and not UIS.MouseEnabled) then
		if MobileSpecific then
			local DeviceSize = workspace.CurrentCamera.ViewportSize; 
			if ( DeviceSize.Y > 600 ) then
				Device = "Mobile(Tablet)"
			else
				Device = "Mobile(Phone)"
			end
		else
			Device = "Mobile"
		end
	else
		Device = "Desktop"
	end

	return Device

end

return Detect

Test Code Running the module:

local Modules = game:GetService("ReplicatedStorage"):FindFirstChild("Modules")
assert(Modules,"Module Folder is Missing")
local DeviceModule = Modules:FindFirstChild("DeviceDetection")
assert(DeviceModule,"Device Detection Module is Missing")
local DeviceDetection = require(DeviceModule)

print(DeviceDetection:GetDevice())

wait(5)

print(DeviceDetection:GetDevice())

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Wait()

print(DeviceDetection:GetDevice())

Output if i wait until the test prints out the first two lines before applying an input:


Output if i apply an input before the second line prints:

Expected behavior

The Expected Output of this is for it to always return the correct device that I am using, but it seems that it only does this in the live game, and not the emulator, and I believe that it is due to the values that I use to check the device type not being correctly updated until after an input for some reason.

A private message is associated with this bug report

Hi,

Thank you for this report.

This behavior is currently legacy issue with the Emulator. We’re working on a project that should mitigate this though we don’t have a definite timeline for this yet.

On the other hand we have created a set of new API-s that should support any input / screen with any device and the recommendation is to use those API-s instead of device detection.

For more, see this announcement and especially our new cross-platform development guide.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.