Search Unity

Array bug??

Discussion in 'Scripting' started by mdeglobal, Aug 19, 2019.

  1. mdeglobal

    mdeglobal

    Joined:
    Feb 22, 2015
    Posts:
    6
    Hi Everyone,

    I have several problems to compile the entire project.
    Array values works well on editor, runtime, etc... but when compile project array values are slided, moved one value up....

    This is normal? please, help with that.. 2019.1.f1v

    thank you!!!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    Hi,

    What kind of array it is? how are you using / initializing it?
     
  3. mdeglobal

    mdeglobal

    Joined:
    Feb 22, 2015
    Posts:
    6
    - - - -
    //create//
    GameObject[] sockets,sockets_ene,sockets_sk,sockets_ene_sk;
    ...
    // initialize//
    sockets = GameObject.FindGameObjectsWithTag("cp_player");
    sockets_ene = GameObject.FindGameObjectsWithTag("cp_ene");
    ...
    // use //
    //ICE
    for (int j = 3; j > 0; j--) { // player
    cont_freeze[j]--;
    Mathf.Clamp(cont_freeze[j], 0, 10);
    if(cont_freeze[j] == 0)
    {
    if (sockets[j].GetComponent<check_prox>().myself)
    {
    sockets[j].GetComponent<check_prox>().myself.GetComponent<states>().freezed = false;
    sockets[j].GetComponent<check_prox>().myself.transform.Find("ice_crystal").GetComponent<Image>().enabled = false;
    // unfreeze sfx //GameObject.Find("sound_manager").GetComponent<sound_manager>().launch_sfx();
    }
    }

    }
    for (int k = 3; k > 0; k--) { // ene
    cont_freeze_ene[k]--;
    Mathf.Clamp(cont_freeze_ene[k], 0, 10);
    if (cont_freeze_ene[k] == 0)
    {
    if (sockets_ene[k].GetComponent<check_prox_ene>().myself)
    {
    sockets_ene[k].GetComponent<check_prox_ene>().myself.GetComponent<states>().freezed = false;
    sockets_ene[k].GetComponent<check_prox_ene>().myself.transform.Find("ice_crystal").GetComponent<Image>().enabled = false;
    // unfreeze sfx //GameObject.Find("sound_manager").GetComponent<sound_manager>().launch_sfx();
    }

    }
    }
    .....
    when sockets[] is fail(slide values up) when compile..... thnx in advance!!
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    i'd check first if this returns the same amount in editor and in build:
    sockets = GameObject.FindGameObjectsWithTag("cp_player");

    try some Debug.Log(sockets.Length);

    If you initialize in Start or Awake,
    some other script with Start, Awake might run before or after.. in that case, can use execution order,
    https://docs.unity3d.com/Manual/class-MonoManager.html
     
  5. mdeglobal

    mdeglobal

    Joined:
    Feb 22, 2015
    Posts:
    6
    Thanks , I´ll try that.... :)
     
    Last edited: Aug 19, 2019
  6. mdeglobal

    mdeglobal

    Joined:
    Feb 22, 2015
    Posts:
    6
    It works! thnx, mgear :)
     
  7. luca59

    luca59

    Joined:
    Aug 17, 2019
    Posts:
    1
    I have a problem which I doubt is unheard of, but for the life of me I cannot find with the search tool. Hence the new topic Myloweslife. My apologies if this is already known and I didn't google it right.
     
    Last edited: Sep 10, 2019