Virtual Buttons

Sergey Bespalov

New member
Hello. I have a trouble with virtual buttons.

1. I switched my build target to Android
2. I added Virtual Controls to my project
3. Started the game

4. Tap the button "Attack". Result: The weapon was firing. (OK)
5. Tap the button "Attack" again. Result: The weapon didn't fire (Not OK)
6. Tap the button "Attack" again. Result: The weapon didn't fire (Not OK)
7. Tap empty space on the screen without any virtual controls.
8. Tap the button "Attack". Result: The weapon was firing. (OK)
9. Tap the button "Attack" again. Result: The weapon didn't fire (Not OK)

So "Attack" button works only if I just started the game or if I have touched empty space on the scree before "Attack" Button.

Other buttons work as expected.

What could cause this problem?

I posted it in wrong forum section. This question about Ultimate Character Controller.
 
Last edited:
Non virtual input had worked before I switched build target to android.
After it only firing was working if I switched unity input to "force standalone". (Can't move and look with mouse and keyboard)

Virtual jump button - works
Virtual reload button - works
Joystic - works
Lookpad - works
 
I am traveling to Unite so I can't directly test it out right now but I did try a small scene and enabled virtual controls with mouse input. It looks like it's getting caught up on line 209 of Use.cs:

Code:
if (m_PlayerInput != null && m_PlayerInput.IsPointerOverUI()) {
The use ability isn't starting because the mouse is over a UI object. This calls IsPointerOverGameObject. I tried disabling Raycast Target on the UI element but that still was triggered.
 
I got some time to take a look at this. Add the following to UnityInput:

Code:
        public override bool IsPointerOverUI()
        {
            // The input will always be over a UI element with virtual inputs.
            if (m_Input is VirtualInput) {
                return false;
            }
            return base.IsPointerOverUI();
        }
 
I got some time to take a look at this. Add the following to UnityInput:

Code:
        public override bool IsPointerOverUI()
        {
            // The input will always be over a UI element with virtual inputs.
            if (m_Input is VirtualInput) {
                return false;
            }
            return base.IsPointerOverUI();
        }

Thx. It works now.
 
Hello. I have another trouble with Virtual Buttons.

They all work great in the Editor.

But when I had built an apk file for Android and installed it on a few devices (Nexus 5, Samsung Galaxy S8) some virtual controls didn't work:

Attack, Jump, Reload - work (OK)
Touchpad - doesn't work
Joystic - doesn't work

Joystic didn't do any reaction to touch - the knobb didn't move.

I tried different build settings - Mono, IL2CPP. - The same result.
What could cause this bug?
That are my player settings and EventSystem:
1540279635107.png

1540279671818.png
1540279713609.png
1540279804025.png

1540279873769.png
 
Justin, I have done some experiments:

1. I added log to VirtualJoystick and VirtualTouchpad.
2. I found out that OnPointerDown was called and OnPointerUp but OnDrag wasn't
OnDrag is never calling on the device.

3. I created an empty project, added Canvas and Image, added a script that implements IDragHandler, IPointerDownHandler, IPointerUpHandler and does logging events.
OnDrag was called on the device as in the Editor. All was OK.

4. Added new Canvas to my project (not new, the old one) and disable the Canvas with Virtual Controls and UI. Adedd an Image, added a script that implements IDragHandler, IPointerDownHandler, IPointerUpHandler and does logging events.
OnDrag was called in the Editor but on the real Device in the build OnDrag was never called.

But there was something strange - after disabling VirtualsControlManager the whole screen of the device was working as touchpad.

Update: OnDrag was called when I had disabled the character
 
Last edited:
I have found the solution.
In the "Unity Input" component. The checkbox "Disable Cursor" should be unchecked. If the cursor is locked then UI elements can't receive OnDrag event on mobile devices.
 
Last edited:
Interesting.. thanks for posting the solution! I'll ensure it is force enabled with the next version.
 
Top