Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Apple Pencil and Enhanced Touch using the new Input System

Discussion in 'Input System' started by edwon, May 11, 2022.

  1. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    260
    I'm trying to get apple pencil input using the EnhancedTouch API in the new package manager input system 1.3.0

    I keep just getting this in the Xcode console when I make a build to iPad and touch the screen with Apple Pencil:

    Received stylus event from a device which shouldn't have supported it. Check IsStylusTouchSupported implementation


    I wish there was just a simple example of how to get Apple Pencil input working and detected separately from finger touches without using the new actions manager thingy which is awful for touch input.

    Code (CSharp):
    1.    
    2. using UnityEngine.InputSystem.EnhancedTouch;
    3. using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
    4.  
    5.     void Awake()
    6.     {
    7.         EnhancedTouchSupport.Enable();
    8.     }
    9.  
    10.     void Update()
    11.     {
    12.         if (Touch.activeFingers.Count == 1)
    13.         {
    14.             Touch activeTouch = Touch.activeFingers[0].currentTouch;
    15.             Debug.Log("Phase: " + activeTouch.phase + " Position: " + activeTouch.screenPosition + " Pressure: " + activeTouch.pressure);
    16.         }
    17.     }
     
  2. XB23

    XB23

    Joined:
    Sep 12, 2018
    Posts:
    20
    Hello, I currently have the same problem, did you find a solution or still stuck ?
     
  3. Lizby

    Lizby

    Joined:
    Dec 21, 2020
    Posts:
    3
    Same here- does anyone know how to fix this? I have tried using Pen.current.position.ReadValue() with the same result..
     
  4. Gruni

    Gruni

    Joined:
    Dec 13, 2012
    Posts:
    4
    I ran into this very issue today and found a solution:

    To get the ApplePencil working, I had to completely disable the old Input System. (Unity 2023.1.9f1)

    Edit -> Project Settings -> Player -> Other Settings -> "Active Input Handling" (2/3rds down) to "Input System Package (New)" instead of "Both"

    After that, I had to ensure that event system in my scene is updated to (just click on event system and the mono behaviour shows an upgrade-prompt). Otherwise, that old event system would fire a ton of Nullpointers on the iPad.

    Once that was done, I was able to get my data via the Pen-Object like this:

    Code (CSharp):
    1. Vector2 pos = Pen.current.position.ReadValue();
    2. float pressure = Pen.current.pressure.ReadValue();
    3. bool isDrawing = Pen.current.tip.isPressed;
    4.  
    The only struggle I have left for now is to make the Pencil interact with Buttons. The eventsystem-Update doesn't do that automatically, it seems.

    Update: I have no idea what happened internally, but after removing and adding all buttons from scratch, it started working just fine. I checked the Button Components value by value and they didn't differ. Yet the new one worked, the old one didn't. I guess internally, these buttons were somehow still linked to the old input system.

    Anyway: Apple Pencil 2 just rocks and feels super fluffy.

    Sidenote: I run it on an iPad Pro M1 and set the Application TargetFrameRate to 120. Feels great.
     
    Last edited: Aug 18, 2023