Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Tutorial: Implementing touch with Input System's Enhanced Touch API

Discussion in 'Input System' started by Yecats, Jul 7, 2020.

  1. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    Hello!

    I've put together a new tutorial that covers how to use the EnhancedTouch API and how to hook up the Input System to the UI. The goal is to give foundational knowledge for beginners to get going.

    Introduction
    User input is a core pillar of an interactive and engaging experience. Once you collect it, it's important you present an experience that feels natural and intuitive to the player. In this tutorial, you'll cover the basics of the new Unity Input System by creating a demo project that can:
    • Place a 3D model by dragging it off the User Interface (UI) and dropping it into the world.
    • Move the camera by dragging one finger.
    • Zoom the camera by pinching two fingers.
    Learning Outcomes
    You'll learn how to:
    • Install the new Input System's package.
    • Enable Touch Simulation mode.
    • Collect and process touch input via the EnhancedTouch API.
    • Route Input System events to the UI.
    Links:
    Thanks!
     
    Last edited: Apr 17, 2021
  2. Iphychoo

    Iphychoo

    Joined:
    Sep 26, 2012
    Posts:
    12
    Found this super useful! Like really useful :D
     
    Yecats likes this.
  3. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    How wonderful, thanks for sharing the feedback!
     
  4. Mika_Do

    Mika_Do

    Joined:
    Apr 1, 2015
    Posts:
    11
    Hey just wanted to give you a heads up !
    Came across the Unity documentation on EnhancedTouch and I couldn't understand anything from it.
    Now after reading your tutorial everything has become very clear and I finally managed to add panning and zooming to my game.

    Thanks a lot !

    Now I need to find out how to rotate :p
     
    Yecats likes this.
  5. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @Mika_Do This is awesome to hear, thanks so much for the feedback! :D

    This tutorial might be helpful - it's one I did for Keyboard/mouse but talks about camera rotating. You'll have to adapt it to the Touch API but hopefully the tutorial taught you everything you need to know for that to be easy. (If it didn't, let me know what's missing and I'll do another short one.)
     
    Last edited: Apr 17, 2021
  6. DeclanHsu

    DeclanHsu

    Joined:
    Apr 9, 2017
    Posts:
    1
    It works. Thanks a lot.:)
    This problem was torturing me for several days. I hate new input system.
     
    Yecats likes this.
  7. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @DeclanHsu Glad to hear it helped! The new Input System is definitely different, but once I figured out how it all worked I came to love it. The old system had so many flaws and was not great when it came to multi device support.. or even just controller support.
     
  8. TwentySicks

    TwentySicks

    Joined:
    Sep 6, 2012
    Posts:
    51
    YES! Finally, a nice clean way to setup camera movement, while supporting multitouch IN THE NEW INPUT SYSTEM!

    I've basically achieved the same, by converting this code; Pinch and Scroll to Move and Zoom in Unity for Mobile Games (github.com) from this Youtube channel Pinch and Scroll to Move and Zoom in Unity for Mobile Games - YouTube

    However I completely misunderstood the EnchancedTouch API, so I fiddled around with the Action map UI thing. After reading the docs on EnhancedTouch I was sure my initial plan (which is exactly what you achieved in the tut) would be easy to implement, but I has misunderstood how it really worked.

    So, thank you @Yecats for this tutorial AND your other ones. Your style of setup for the tutorial texts + GIF's is so great, and it resonates exactly with how I would have made a tutorial, if i wasnt such a lazy bastard! Thanks you!
     
    Yecats likes this.
  9. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @TwentySicks Well this made my Sunday afternoon! Thank you for taking the time to write and let me know that the tutorial was useful. :D
     
  10. TwentySicks

    TwentySicks

    Joined:
    Sep 6, 2012
    Posts:
    51
    No problem at all, keep up the good work. Did you make some of those low poly 3D models? If so, it would be awesome with a tutorial on that as well ;)
     
  11. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @TwentySicks I made the ones in this tutorial and the witch in the other Input System series. I've been slowly teaching myself how to model - you can see what I've done on my SketchFab.

    I have been discovering best practices and good Blender scene setup for making modular assets that import well into Unity. I was thinking about making a tutorial that covered that once I got a good feel for the workflow. The minecart was my first attempt. I think it turned out pretty well - all of the train track pieces snap together perfectly. (Took some trial and error!)

    upload_2020-12-14_11-59-5.png

    And the last couple of days I've been working on a Christmas set.
     
  12. TwentySicks

    TwentySicks

    Joined:
    Sep 6, 2012
    Posts:
    51
    For the love of all that is holy, if you can manage to make a tutorial for that, in the same style and setup as the other ones, my life will be complete! I've tried following along at making some low-poly stuff in Blender before, but i've never seemed to understand it properly. Might finally brush up on it, if you release something like that!

    Also, in case you need ideas, it would be cool if you added a "chapter" about rotating the camera in the Touch input tutorial! The tutorial video which I linked in my first reply shows the effect I'm interested in.
     
    Yecats likes this.
  13. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @TwentySicks I'm so sorry, I missed your response until now! I had a good laugh at "for the love of all that is holy". :D I've put the tutorial writing on hold for the holidays but am planning on starting back up in January.

    I've added the suggestion for rotating with EnhancedTouch API to my tutorial backlog. Thanks so much - in looking at the video I think it'll be do-able without any issues. But, if I had a dime for every time I thought that....
     
  14. ManjitSBedi

    ManjitSBedi

    Joined:
    Mar 8, 2014
    Posts:
    58
    Thanks for making this tutorial; you are about to save me some time for sure!
     
    Yecats likes this.
  15. rjparker

    rjparker

    Joined:
    Oct 31, 2020
    Posts:
    3
    Thank you for shedding some light on a dark and scary place (ie EnhancedTouch). I think I now have what I need to continue developing a multi-touch project. :)
    Just for feedback, I had some issues when I tried to follow the "Set up the UI for building placement" section. I got stuck after clicking on the Replace with InputSystemUIInputModule button. Where your GIF shows that the Action Asset is set as DefaultInputAction, I only get None (Input Action). When I look in the Final Project version, it says Missing Input Action in the same field. I assume this problem is a result of running the scenes in Unity 2020.3.19f1 Personal, which did some "upgrades" to the projects. I did try running the tutorial using UnityHub on 2019.4.18f1, but then it complained that the project had been created on an earlier editor and, after it attempted an "upgrade", nothing worked.
    I'm going to have a look at your behaviour trees tutorial now. Looks very interesting.
     
  16. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @rjparker Thanks for the heads up that the project is broken! Sounds like I need to upgrade it to a newer editor version - I'll try to get that fixed up this weekend.

    Glad to hear the tutorial was still helpful. :) Hopefully the behavior tree one is as well.
     
  17. rjparker

    rjparker

    Joined:
    Oct 31, 2020
    Posts:
    3
    I don't know if this will help, but when I made a fresh project under 2020.3.19 and followed your procedure, the DefaultInputAction appeared as intended, and I find that it is located in C:\Users\rjpar\Documents\Unity\BabySteps\SpaceHabitat\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Plugins\PlayerInput
    When I look at the similar location in my attempts at your tutorial, it is also there, but is not recognised by the editor.

    I tried dragging it to the "Missing Input Action" field, but it wouldn't take.
    Maybe I messed up the InputSystem install by trying to run the FinalProject first? I really don't know what I'm doing most of the time, but hopefully it is called "learning".
     
    Yecats likes this.
  18. hosseinpanahloo

    hosseinpanahloo

    Joined:
    Jun 28, 2018
    Posts:
    11
    Great tutorial. Thank you so much :)
     
    Yecats likes this.
  19. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    71
    @rjparker I finally had a chance to open up this tutorial in 2020.3.20f1. I'm not getting any weird errors when I look at the input module in either the starting or final project. In fact, it was probably the smoothest upgrade I've ever had with Unity - everything is as expected.

    I'm not sure what you did - but it sounds like perhaps it's something funky on your end? Perhaps you should try a later LTS for 2020.3?

    "I really don't know what I'm doing most of the time, but hopefully it is called "learning"." <-- This gave me a good laugh. Definitely how I learn as well. :D
     
  20. jjfawkes

    jjfawkes

    Joined:
    May 28, 2013
    Posts:
    12
    @Yecats thanks for the tutorial, it's very useful. It's the only tutorial I have found that covers the EnhancedTouchSupport. It's very strange there aren't more tutorials covering basic panning & zooming with the new input system. Others that I found were badly implemented.
     
    GDevTeam and Yecats like this.