Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Buttons not working on mobile

Discussion in 'Android' started by Zaba200, Apr 6, 2020.

  1. Zaba200

    Zaba200

    Joined:
    Aug 25, 2017
    Posts:
    4
    Hello, so I have a problem that I would really need help with. I have a project with a shop. every other UI works fine, I have two buttons named shop and back that work perfectly but when it comes to the shop elements or just this specific one it doesn't work, I am not sure if it's only this or all shop buttons but when you click on it it should display a menu to accept your purchase but it doesn't it works fine in the editor but every time I open my game on android the button it does nothing, it does change color when clicked as set on the button component but when I click on it it just does nothing, it does not open the menu if you have enough money or not. I am not sure if this has to do with the actual UI or with the mechanics but i am not sure its the mechanics because the code checks for money and if the condition is not met the "not enough money menu" opens in the else statement, maybe there is a thing that UI don't show as expected on mobile?. but again i did set my Canvas to scalable so i don't think that is the problem as well. please help I have no idea what to do. Here are some pictures below as well.



    Thanks to everyone that will take some time and help me with this problem. :)
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    I can't tell you what the problem is but I may be able to get you to a point where you can find out what is happening. I just put a project on Android yesterday and it was problems right from the start.

    I installed the Android Logcat package, and it really help me narrow down where my problems where.

    One of the problems I had was my GameManager was supposed to run before everything, worked fine in the editor, once built to the device it didn't work anymore. I set the script execution order to ensure it runs before everything else and solved quite a few problems.

    Issues are easier to track down when you can actually see what is causing them. I had some buttons that wouldn't work while others worked fine, logcat showed me it was null reference exceptions causing them to not work. Most of it tracked back to the GameManager not running first before everything. I also had a few static fields that needed to be reset when a new scene was loaded, among other things not being set at all on scene load from my GameManager that is set to DontDestroyOnLoad.
     
  3. Zaba200

    Zaba200

    Joined:
    Aug 25, 2017
    Posts:
    4
    Hy so thanks for your reply first of all and second I managed to get the console working with your help and here is what it says that is wrong it just says that it's trying to access a null reference as you can see in this picture but I still have no clue how to fix this. i was also playing around with the execution order but with no success.
    https://i.imgur.com/n3uOpXg.png
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    There is a null reference exception in PlaneOffer.PlaneBuy(). Use some debug.log statements and find out what is null in that method.
     
  5. majorapplesauce

    majorapplesauce

    Joined:
    Jun 15, 2013
    Posts:
    13
    Now, this maybe a swing and a miss. But i had a similar issue that only happened on Android. It also only happened on the device and not in the editor, so this might be different. After about 2-3 days of going crazy. I found out that my null reference was on my API calls that my buttons were doing. I couldn't figure out why for the life of me that this was happening as the API's are working just fine.

    Then, it dawned on me. There is an Internet access option in the player settings that MUST be set to required if going on an Android device. After doing that my null reference issues went away, the API's worked and so did my buttons.
     
    DianaCode3 likes this.
  6. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    146
    In case it helps someone: I had a similar issue. There was code that didn't get executed on a non-mobile platform, e.g.
    #if UNITY_ANDROID
    or in my case:
    Code (CSharp):
    1. if (SystemInfo.supportsGyroscope) {...}
    This really helped me:
    Make a new MonoBehaviour
    Code (CSharp):
    1. public TextMeshProUGUI reportErrorTextObject;
    2. void Awake()
    3.     {
    4.         if (reportErrorTextObject== null)
    5.         {
    6.             reportErrorTextObject = GetComponent<TextMeshProUGUI>();
    7.         }
    8.         Application.logMessageReceived += HandleLog;
    9.     }
    10.  
    11. void HandleLog(string logString, string stackTrace, LogType type)
    12.     {
    13.         output = logString;
    14.         if (type == LogType.Exception || type == LogType.Error)
    15.         {
    16.             reportErrorTextObject.text = stackTrace + "\n" + output + "\n";
    17.          }
    18.     }
    Put the MonoBehaviour on a Text mesh pro object. For me I added some stuff like: Check if the message was the same as the previous one and then skip it, and a clear button, but you get the point.
     
  7. ArturRimDev

    ArturRimDev

    Joined:
    May 28, 2021
    Posts:
    1
    my buttons are not working on my android build
    the simple TMPro buttons
     
    heartingNinja likes this.
  8. Harshipro

    Harshipro

    Joined:
    Oct 9, 2020
    Posts:
    11
  9. YassineSkorpion

    YassineSkorpion

    Joined:
    Jul 18, 2022
    Posts:
    2