UI button SetActive() resets the Onscreen stick position.

I am making a game for Mobile and am trying to make an on screen button appear and disappear when my character enters a collider trigger. I am using button.SetActive(true/false) function to make the button appear and disappear. The button seems to work fine and it does show and hide as expected. But I am experiencing a very weird and different problem. Every time the setActive for the button is called, the on Screen Joystick position resets itself to center stopping my character immediately. My controls are supposed to be very sensitive.

To fix this I tried to put the button on a separate Canvas. Still the same.

The problem exists on the Unity Game window when I use my mouse to move the on screen Joystick as well as on the mobile.

Any clues on why this is happening and how to fix it?

  • I am using Unity 2020.1.2f1 Personal
  • am using the New Input System with On-Screen Stick Component and overriding “Left Stick of Gamepad” for joystick.
  • am using OnTriggerEnter/OnTriggerExit fuctions to SetActive(true/false)

I found a working solution. Maybe it’s not the best approach but this is what I did.

  • I added a component to my existing onscreen button.
  • I am using the Button component’s features to hide the button.
  • I use setIntractable to true and false instead.

It works fine now.