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. Dismiss Notice

Best way to manage different platform targets?

Discussion in 'General Discussion' started by erdostamasa, Feb 3, 2022.

  1. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    What is the best way to manage the same project for different build targets?
    For example, I'm a solo dev working on a game. Currently it has keyboard and mouse controls, but I would like to add virtual jojysticks and build it for mobile. What is the most efficient way to manage and develop a game with multiple control modes like this?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
  3. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    Damn I should get into the new input system :D
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    There were examples for the old input systems too, but I don't recall where they were. A joystick UI is not that hard to code either, so you could do it on your own if you wanted.
     
    erdostamasa likes this.
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    The fastest way to set up virtual controls is to download one of the Starter Assets from Unity. They contain a full-fledge virtual joystick solution. You can take that from there and also see how to set up one properly. (New Input System, obviously)
     
  6. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    I can add mobile controls, my question was about managing the 2 different input systems (PC and mobile) at the same time.
     
  7. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    That's more or less (more) automatic in the new input system. Basically you add or remove the virtual joysticks on screen based on your target platform. The input system handles almost everything automatically AFAIK. (I only work with keyboard/mouse and gamepads, I don't target mobiles, but I assume there aren't too many differences and the virtual joys work out of the box even on PC build)
     
    erdostamasa likes this.
  8. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    The new input system does this as well as you can expect. You set up a Horizontal axis for example, and the code reacts the same regardless of what input device is used for that axis. You also can use a Pointer, which will be a mouse on desktop, and a touch on mobile and touch screens.

    I haven't find a way to test things like a Pinch without building to the device, so you still have to build to your device to really test everything. Overall, once you get the hang of the new input system it feels less 'hacky' than all the previous solutions I've tried.
     
    erdostamasa likes this.
  9. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    Thanks for the answers, I will finally make myself learn the new system :D

    Are there any tips how should I handle platform-specific GameObjects, like UI for example?
    I would need additional UI buttons on mobile to access functionality that would be keyboard on desktop. Should I just make a script that disables those objects if platform == desktop ?
     
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    Use Addressables. https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/AddressableAssetsProfiles.html
    You can add assets just for specific target platforms and you can load them on specific platforms (using #if).
     
  11. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    I've never disabled keystrokes when setting up the UI Bindings. It's a bit of a bear, but you set 'bindings' to interactions. A binding can have several ways it's triggered, i.e. a swipe, a key press, etc. Since a mobile device doesn't really have a keyboard, it will never be pressed so why worry about it?

    The other odd thing to consider is touch screens, tablets and phablets. They all sort of blend together as devices. I needed to reduce clutter on an interface so I used an #if define to identify Handheld devices, but some Windows tablets identify themselves as handhelds and I wanted tablets to have the additional elements.

    The only workaround I could figure out was to use another #if to identify iPads. So an iPad will have the additional elements, but anything else calling itself a handheld will not. There are so many Android devices in all sizes I just can't worry about them, so some tablets will get the handheld version.
     
    erdostamasa likes this.
  12. erdostamasa

    erdostamasa

    Joined:
    Mar 28, 2020
    Posts:
    32
    Thanks for the tips!
    I never said I disabled keystrokes, I wanted to disable the mobile UI buttons that substitue for the keyboard when on PC. For example, on mobile I need a pause button, or a shoot button but on PC I can just use ESC or left click. I'd like to disable those buttons on PC builds and enable them on mobile.