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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Method hangs on Android, but works in editor

Discussion in 'Android' started by profsteven7, Sep 20, 2018.

  1. profsteven7

    profsteven7

    Joined:
    Jun 14, 2016
    Posts:
    6
    The menu part of my app works fine in the editor. It activates and deactivates various canvas game objects based on user selections. BUT... when I build and run this app on my Samsung Android phone and select "Game Menu" on the main menu, it would stall, not do any of the statements in the GoToGameMenu method.

    To help debug the app, I linked the Game Manager method to a little SoundFX class with a PlayBeep method. What's so crazy is that wherever I put the PlayBeep call in the GoToGameMenu method, when I ran the app on my Android phone, it would run the statements up to and including the beep, and then stall. When I finally put the playBeep call at the end of the method, it would run every statement in the method correctly. But if I remove the playBeep call from the method, it returns to not running any statements from this method. Does anyone have any ideas on why this method only works on Android when an external method call like this is included and only up to and including it, and nothing past it? I'm really hoping to avoid having to put the workaround all throughout my code just to make methods work. Thanks!

    Here's the stalling method that's contained in my Game Manager monobehaviour class. In this version, it actually runs every statement ONLY because the playBeep is included at the end:

    #region GoToGameMenu
    public void GoToGameMenu()
    {

    currentMenu = "game";

    mainMenu.SetActive(false);

    //Game Menu setup
    genMenuGameObject.SetActive (true);

    genMenu.title.text = "Game Menu";
    genMenu.prompt.gameObject.SetActive (false);
    genMenu.option1.gameObject.SetActive (true);

    if (PlayerPrefs.HasKey ("game")) {
    LoadGameData();
    genMenu.option1Text.text = "Continue Game";
    genMenu.option3.gameObject.SetActive(true);
    genMenu.option3Text.text = "End Game";
    } else {
    genMenu.option1Text.text = "New Game";
    genMenu.option3.gameObject.SetActive(false);
    }

    genMenu.option2.gameObject.SetActive(false);
    genMenu.option4.gameObject.SetActive(false);
    genMenu.okButton.gameObject.SetActive (false);
    genMenu.backButton.gameObject.SetActive (true);
    genMenu.backText.text = "back";

    // BEEP SOUND
    SoundFX.PlayBeep ();

    }
    #endregion




    Separate class containing the playBeep method:

    public class SoundFX: MonoBehaviour {

    public AudioClip beepSound;
    private AudioSource audioSource;

    void Awake () {
    audioSource = GetComponent<AudioSource>();
    }

    public void PlayBeep () {
    audioSource.PlayOneShot (beepSound, 0.5f);
    }

    }


    Unity 5.2.2, Samsung Galaxy J3 running Android 6.0.1
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide your device logs via adb logcat
     
  3. profsteven7

    profsteven7

    Joined:
    Jun 14, 2016
    Posts:
    6
    FIXED: android was hanging because my internal debug method was trying to write to a debug.txt file. writing to that file works on my PC, but Android couldn't find the path and was crashing.

    Found this looking at logcat, so thanks JeffUnity3D for the suggestion.