# 4. Device Simulator and Safe Area Part of [[Mobile Input and Touch]]. Prev: [[3. On-Screen Stick and Isolated Actions]]. Next: [[5. Worked Example On-Screen Stick Player]]. The **Device Simulator** is built into the Unity 6 Editor. It is not a package you must add in order to open a Simulator view (an optional **Device Simulator Devices** package exists for extra device definitions - confirm the current package page before you pin a version; this series does not invent one). Official 6000.5 introduction: [Device Simulator introduction](https://docs.unity3d.com/6000.5/Documentation/Manual/device-simulator-introduction.html). Use it to **see layout** (notches, safe area, orientation) and to click a single simulated finger onto an on-screen stick. Do not use it as proof that the build is fast, pretty, or multitouch-correct. ## 4.1 What the Simulator view actually does Official capabilities the Simulator view simulates: - Auto-rotation - Screen safe area - Touch input (with the limits below) It reacts to these **Player Settings** the way a real device would, official list: Fullscreen Mode, Resolution Scaling, Default Orientation, Graphics API, Render outside safe area. **Simulated touch input (official, read this twice):** - Input is simulated **only in Play Mode**. - A mouse click on the simulated screen becomes touch events in whichever input solution is active (Input Manager, Input System, or both, per project settings). - The Device Simulator **does not support multitouch**. It can only simulate **one** finger. ## 4.2 Official limitations (do not argue with them in a writeup) The Simulator is for layout and basic interaction. It is **not** an accurate picture of how the application runs on the device. Official "does not simulate" list: - Performance (CPU, memory). - Rendering capabilities of the device. - Native plugins that do not work in the Editor. - Platform `#define` directives for the simulated device, such as `UNITY_IOS`. `#if UNITY_IOS` code will **not** compile-in just because you picked an iPhone in the dropdown. - Gyroscope rotation. Only **one** Simulator view is active at a time (the official "active Simulator view" rules: one Simulator and no Game view → that Simulator is active even if hidden; several Simulators and no Game view → last focused; mix of Simulator and Game views → focusing a Game view disables simulators, focusing a Simulator keeps it active while focused). If your stick "dies" when you click the Game view, this is why. Not every API on the simulated classes is implemented. Official docs send you to **Simulated classes** for the list. If `Input.gyro` or a similar call looks wrong, check that page before blaming your script. ## 4.3 Safe area and orientation Notches and home indicators eat the corners where you want a stick. Official runtime rect: [`Screen.safeArea`](https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Screen-safeArea.html) - a `Rect` in **pixels**, in screen space, that is safe to put UI in. It can change when the player rotates the device. The following script is a classroom helper. It was **not compiled** in Unity. It maps a `RectTransform` parented to a full-screen Canvas (Screen Space Overlay, or a Camera canvas whose size matches the screen) onto `Screen.safeArea`. Confirm the anchor math on a Simulator device with a notch, in both portrait and landscape. ```csharp using UnityEngine; /// <summary> /// Stretches a RectTransform to Screen.safeArea. /// NOT compiled in Unity. Parent this to a full-screen Canvas rect. /// </summary> [RequireComponent(typeof(RectTransform))] public sealed class SafeAreaFitter : MonoBehaviour { RectTransform _rect; Rect _applied; void Awake() => _rect = (RectTransform)transform; void OnEnable() => Apply(); void Update() { if (_applied != Screen.safeArea) Apply(); } void Apply() { var safe = Screen.safeArea; var screen = new Vector2(Screen.width, Screen.height); if (screen.x <= 0 || screen.y <= 0) return; _rect.anchorMin = new Vector2(safe.xMin / screen.x, safe.yMin / screen.y); _rect.anchorMax = new Vector2(safe.xMax / screen.x, safe.yMax / screen.y); _rect.offsetMin = Vector2.zero; _rect.offsetMax = Vector2.zero; _applied = safe; } } ``` Put the stick **inside** the fitted rect, anchored to a thumb corner, with a hit area at least as large as your accessibility target-size rule ([[Accessibility]]). Default Orientation and autorotate are Player Settings: pick what the assignment allows (portrait-only is easier; both orientations means you re-check the stick in both). `Screen.orientation` exists for reading / requesting orientation; if you use it, confirm the 6000.5 Scripting Reference and remember the Simulator's autorotate support is layout-level, not a performance test of a rotate animation. ## 4.4 A phone still has to exist Before you claim the slice "works on mobile": 1. Layout in the Simulator (notch device, portrait and landscape if you support both). 2. One-finger stick drag in Play Mode in the Simulator. 3. A **player build** on a physical phone for multitouch, pressure, thermal/performance, and any `#if UNITY_ANDROID` / `UNITY_IOS` path. The Simulator will not catch those. ## 4.5 Exercise Pick a Simulator device that shows a notch. Apply `SafeAreaFitter` to a panel, put a stick in the lower-left of that panel, rotate to landscape, and screenshot both orientations. Then open a Game view and confirm you understand which view is the **active** simulator. Write one sentence in the assignment about the no-multitouch limit so you do not "fail" a two-finger gesture in the Editor. ## Sources - Device Simulator introduction (6000.5): https://docs.unity3d.com/6000.5/Documentation/Manual/device-simulator-introduction.html - `Screen.safeArea` (6000.5): https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Screen-safeArea.html - [[Accessibility]]