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

static variable - diffent bevahiour when building APK - know bug?

Discussion in 'Scripting' started by mm_unity870, Apr 15, 2020.

  1. mm_unity870

    mm_unity870

    Joined:
    Feb 7, 2020
    Posts:
    8
    Hi all,

    when I play my game in the unity editor I am using a static variable to memorize some data in case I have to reload the scene (using the LoadScene-statement ). This works fine .
    But when I build an APK and deploy on my phone the value of the static variable seems to get lost!

    After the LoadScene-statement the variable get's it default-value and not the expected/memorited value.

    Has anybody had the same behaviour?

    Thanks, regards
    Mario
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,970
    Make the static be a property and log it when it changes, then run
    adb logcat
    to see if the behavior is different on Android vs the Unity engine.

    It would look something like this and you would only ever access
    data
    , never
    _data
    .

    Code (csharp):
    1. static string _data;
    2. public static string data
    3. {
    4.  get
    5.  { return _data; }
    6.  set
    7.  {
    8.    Debug.Log( "data was changed to '" + value + "'");
    9.    _data = value;
    10.  }
    11. }
     
  3. mm_unity870

    mm_unity870

    Joined:
    Feb 7, 2020
    Posts:
    8
    Hi Kurt,

    many thanks.

    But I wonder how to access the log on an android phone?
    Do you mean I should run the APK on an emulator? I have no experience doing this :-(

    Thanks, regards
    Mario
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,970
    Look online how to use
    adb logcat
    . It's part of the Android SDK toolchain.
     
  5. mm_unity870

    mm_unity870

    Joined:
    Feb 7, 2020
    Posts:
    8
    Hi Kurt,

    thanks. I will have a look.

    Thanks, regards
    Mario