Search Unity

Question How to handle input in an Asset Store asset project?

Discussion in 'Input System' started by pumpkinszwan, May 1, 2023.

  1. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I am building a project for release on the Asset Store, and I need to implement some input to detect mouseover, clicks, and so on. Basic UI input.

    My current project is built with the new Input System, but I just realised that this may not be a good idea for users importing the asset into an existing project as they would probably already have input setup (and they may be using the old input method or the new Input System).

    Is there a best practice for this scenario? At the moment I am thinking of just downgrading to the old input style and having some documentation to guide users to modify the scripts to use the new Input System, but that feels a bit clumsy.

    Another option could be just including my own Input System config OR just old input style, and let the user sort out the input. However, I would prefer to keep my asset as 'plug and play' as possible.

    Any input or ideas would be appreciated.
     
    Mikamue likes this.
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,043
    If the code is crucial there are a few things you can do:
    1. Make it clear in docs it uses the new input system and maybe have a dependancy om the package.
    2. Use the input system define to make the code work for both new and old input systems. This is more work, but very professional

    If the code isn't too crucial I generally recommend for them to use the old input system, but as long as it's stated clearly it should be fine
     
    Mikamue and pumpkinszwan like this.
  3. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Oh, that's the answer, thanks! I really wanted to support both systems, but didn't realise it was so simple to implement.

    For future reference:

    #if ENABLE_INPUT_SYSTEM
    // New input system backends are enabled.
    #endif

    #if ENABLE_LEGACY_INPUT_MANAGER
    // Old input backends are enabled.
    #endif

    // NOTE: Both can be true at the same time as it is possible to select "Both"
    // under "Active Input Handling".

    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Migration.html
     
    Mikamue and DevDunk like this.