Search Unity

Full Switch Case Not Being Executed

Discussion in 'Scripting' started by Resilo, Apr 10, 2019.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    when the following script is executed in the unity editor the only part that works is Debug.Log("got");

    When i run a built stand a lone client this entire case code executes no problem

    But when i run it in the unity editor the only line that is executed is Debug.Log("got");
    i do not receive any message for Debug.Log(whosentit.localusername); or any other console messages of any type regarding the execution of the case


    furthermore
    I have debugged the whole case and every component possible and it is all working correctly.

    I am mainly wondering about situations where a case such as this one stops with no error message

    or known unity editor glitches where this can occur? or can there exists a condition where the switch is activated at the same time with 2 separate cases that can lead to an early break?

    the only function i can get to work other then the Debug.Log("got"); is if i add a bool and change it to true or false


    Code (CSharp):
    1.                 case 3:
    2.                     Debug.Log("got");
    3.                     localplayerobject.GetComponent<Menu>().challengwindoopen.SetActive(true);
    4.  
    5.                     recivedbattlerequest whosentit = JsonUtility.FromJson<recivedbattlerequest>(content);
    6.                     Debug.Log(whosentit.localusername);
    7.                     localplayerobject.GetComponent<Menu>().challenger.text = "Challenger: " + whosentit.localusername;
    8.                     localstats.playerpartymine = whosentit.playerpartymine;
    9.  
    10.                     localstats.challenger = whosentit.localusername;
    11.                     localplayerobject.GetComponent<playerstats>().beingchallenged = true;
    12.  
    13.                     break;
     
    Last edited: Apr 10, 2019
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Have you attached the debugger to Unity, placed a breakpoint at Debug.Log("got"), and see what happens when you step to the next line?
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The username might be blank. Try

    Debug.Log("Sent by: " + whossentit.localusername.ToString());

    Also, you might consider a try/catch block, might be throwing an exception.
     
  4. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    thanks finally an error to work with
    Code (CSharp):
    1. UnityEngine.UnityException: GetComponentFastPath can only be called from the main thread.
    2. Constructors and field initializers will be executed from the loading thread when loading a scene.
     
    Last edited: Apr 10, 2019