[Solved] Unity freezes instantly when I press play.

Everything was working fine with my project and I restarted unity, then this error appeared:

Error loading launcher://unity/C:/Users/board/AppData/Roaming/Unity/Packages/node_modules/unity-editor-home/dist/index.html?code=WKNGXdjiaFUJv0TkkQKgaQ01bf&locale=en&session_state=2dd79b3d7a37ac830c39e5dcde83c8cd3a3dc9a5fdf6b341a2a9d146a2b0b9c7.dDFKCI2oLBsC4whXIB_kHw009f#/login

I looked it up and people said the error doesn’t have any impact. So I tried disabling scripts and I found a script that, when disabled unity works fine. I don’t understand why as my project was working just fine and I havent changed anything.

Here’s the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Human_Master : MonoBehaviour {

    Vector3 nulll = new Vector3(0, 0, 0);
    Quaternion nothing = new Quaternion(0, 0, 0, 0);

    public Transform slot1;
    public Transform slot2;
    public Transform slot3;
    public Transform slot4;
    public Transform slot5;
    public Transform slot6;
    public Transform slot7;
    public Transform slot8;

    public GameObject card1;
    public GameObject card2;
    public GameObject card3;
    public GameObject card4;
    public GameObject card5;
    public GameObject card6;
    public GameObject card7;
    public GameObject card8;
    public GameObject card9;
    public GameObject card10;
    public GameObject card11;
    public GameObject card12;
    public GameObject card13;
    public GameObject card14;
    public GameObject card15;
    public GameObject card16;
    public GameObject card17;
    public GameObject card18;
    public GameObject card19;
    public GameObject card20;
    public GameObject card21;
    public GameObject card22;
    public GameObject card23;
    public GameObject card24;
    public GameObject card25;
    public GameObject card26;
    public GameObject card27;
    public GameObject card28;
    public GameObject card29;
    public GameObject card30;
    public GameObject card31;
    public GameObject card32;

    private Player_Master pMaster;

    public GameObject gameManager;

    private Cards_Deal cDeal;

    private GameManager_Master gmMaster;

    void OnEnable () {
        SetInitRefs();
        pMaster.EventFirst4CardsOnHand += GiveCards;
        pMaster.EventAllCardsOnHand += GiveCards2;
    }

    private void OnDisable()
    {
        pMaster.EventFirst4CardsOnHand -= GiveCards;
        pMaster.EventAllCardsOnHand -= GiveCards2;
    }

    void Update () {
       
    }

    void SetInitRefs()
    {
        pMaster = GetComponent<Player_Master>();
        gmMaster = gameManager.GetComponent<GameManager_Master>();
        cDeal = gameManager.GetComponent<Cards_Deal>();
    }

    void GiveCards(int[] c)
    {
        Debug.Log("GiveCards");

        int a = c[0];

        var go = GameObject.FindGameObjectWithTag(a.ToString());
        go.transform.localPosition = nulll;
        go.transform.parent = slot1.transform;
           
        int a1 = c[1];
        var go1 = GameObject.FindGameObjectWithTag(a1.ToString());
        go1.transform.localPosition = nulll;
        go1.transform.parent = slot2.transform;  

        int a2 = c[2];
        var go2 = GameObject.FindGameObjectWithTag(a2.ToString());
        go2.transform.localPosition = nulll;
        go2.transform.parent = slot3.transform;       

        int a3 = c[3];
        var go3 = GameObject.FindGameObjectWithTag(a3.ToString());
        go3.transform.localPosition = nulll;
        go3.transform.parent = slot4.transform;
       
    }

    void GiveCards2(int[] b)
    {

        Debug.Log("GiveCards2");

        int a = b[0];

        var go = GameObject.FindGameObjectWithTag(a.ToString());
        go.transform.localPosition = nulll;
        go.transform.parent = slot5.transform;

        int a1 = b[1];
        var go1 = GameObject.FindGameObjectWithTag(a1.ToString());
        go1.transform.localPosition = nulll;
        go1.transform.parent = slot6.transform;

        int a2 = b[2];
        var go2 = GameObject.FindGameObjectWithTag(a2.ToString());
        go2.transform.localPosition = nulll;
        go2.transform.parent = slot7.transform;

        int a3 = b[3];
        var go3 = GameObject.FindGameObjectWithTag(a3.ToString());
        go3.transform.localPosition = nulll;
        go3.transform.parent = slot8.transform;

    }
}

Please excuse the bad code I am very new to coding, I know its possible to do it way more efficiently

Thanks for any help in advance

public Transform slot1;
    public Transform slot2;
    public Transform slot3;
    public Transform slot4;
    public Transform slot5;
    public Transform slot6;
    public Transform slot7;
    public Transform slot8;
    public GameObject card1;
    public GameObject card2;
    public GameObject card3;
    public GameObject card4;
    public GameObject card5;
    public GameObject card6;
    public GameObject card7;
    public GameObject card8;
    public GameObject card9;
    public GameObject card10;
    public GameObject card11;
    public GameObject card12;
    public GameObject card13;
    public GameObject card14;
    public GameObject card15;
    public GameObject card16;
    public GameObject card17;
    public GameObject card18;
    public GameObject card19;
    public GameObject card20;
    public GameObject card21;
    public GameObject card22;
    public GameObject card23;
    public GameObject card24;
    public GameObject card25;
    public GameObject card26;
    public GameObject card27;
    public GameObject card28;
    public GameObject card29;
    public GameObject card30;
    public GameObject card31;
    public GameObject card32;

That is eye-rape. I’ll never be able to unsee that.

Looks like you need to learn how to use Arrays and Lists. And by “need” I mean MUST.
Pretty much 90% of that code can be condensed into this:

    public GameObject[] Cards;

    void GiveCards()
    {
        foreach (GameObject Card in Cards)
        {
            // do stuff
            Debug.Log("There is a card named " + Card.name + " here!");
        }
    }

Here’s good reading on Lists:

There is no point in debugging such hopelessly bad code, because whatever you fix there will need to be re-written anyways. Projects get confusing enough even with decent code; writing code like that will eventually make you punch your monitor in frustration. It might seem to work now, but later down the road, it will be near impossible.

I understand you’re new to coding, I was at a point when I knew nothing about programming too. But when you see something that’s obviously wrong, or even if you suspect there’s a better way to do something, ask! Many of my questions are just asking if there’s a better way to do what I’m doing. To prove my point:

Those are all questions I asked as a moderately-knowledgeable hobby developer. So please, don’t knowingly write bad code like that.

Let me try to explain a List in a nutshell. A list stores an amount of variables. To create an list of strings, do this:

public List<string> MyStrings;

You’ll see that in the Inspector, like this:
3189372--243491--upload_2017-8-19_14-48-59.png

The Size is the amount of objects in that List (the Inspector looks the same for an Array). Set the Size to the amount of objects you want in the list. Let’s do 10.
3189372--243492--upload_2017-8-19_14-50-5.png

Remember, Lists and Arrays start from 0, so even though the size is 10, the elements go from 0 to 9.

Now, to add to the List, you can simply type in the Inspector. If you need to add to the list in code, you can type

MyStrings.Add("HiThere");

Finally, to iterate for every objects in a List, do this:

void ReadNamesInList()
    {
        foreach(string str in MyStrings)
        {
            Debug.Log("My name is " + str);
        }
    }

Not as hard as you thought, right? So do yourself a favor, don’t waste time writing bad code then wondering what’s wrong with it, and at least try to write decent code. If you have questions, ask away!

Thanks for the advice, I’ll have a look into it and yes I was kind of just trying to work out how to code :'D

Okay, so I tried to tidy up my Code a little and find out were the problem lies, but I can’t find anything.
Maybe you could help me again, here are my 4 classes:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_Master : MonoBehaviour {

    public delegate void CardEventHandler();
    public event CardEventHandler EventFirst4CardsOnHand;
    public event CardEventHandler EventAllCardsOnHand;

    public void CallEventFirst4CardsOnHand()
    {
        EventFirst4CardsOnHand();
    }

        public void CallEventAllCardsOnHand()
    {
        EventAllCardsOnHand();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Human_Master : MonoBehaviour {

    Vector3 nulll = new Vector3(0, 0, 0);
    Quaternion nothing = new Quaternion(0, 0, 0, 0);

    public List<GameObject> cards;

    public List<Transform> slots;

    private Player_Master pMaster;

    public GameObject gameManager;

    private Cards_Deal cDeal;

    private GameManager_Master gmMaster;

    void OnEnable () {
        SetInitRefs();
        pMaster.EventFirst4CardsOnHand += GiveCards;
        pMaster.EventAllCardsOnHand += GiveCards2;
    }

    private void OnDisable()
    {
        pMaster.EventFirst4CardsOnHand -= GiveCards;
        pMaster.EventAllCardsOnHand -= GiveCards2;
    }

    void Update () {
       
    }

    void SetInitRefs()
    {
        pMaster = GetComponent<Player_Master>();
        gmMaster = gameManager.GetComponent<GameManager_Master>();
        cDeal = gameManager.GetComponent<Cards_Deal>();
    }

    void GiveCards()
    {
        Debug.Log("GiveCards");

        int[] c;

        c = cDeal.cards8;

        int a = c[0];

        var go = GameObject.FindGameObjectWithTag(a.ToString());
        go.transform.localPosition = nulll;
        go.transform.parent = slots[0].transform;
           
        int a1 = c[1];
        var go1 = GameObject.FindGameObjectWithTag(a1.ToString());
        go1.transform.localPosition = nulll;
        go1.transform.parent = slots[1].transform;  

        int a2 = c[2];
        var go2 = GameObject.FindGameObjectWithTag(a2.ToString());
        go2.transform.localPosition = nulll;
        go2.transform.parent = slots[2].transform;       

        int a3 = c[3];
        var go3 = GameObject.FindGameObjectWithTag(a3.ToString());
        go3.transform.localPosition = nulll;
        go3.transform.parent = slots[3].transform;
       
    }

    void GiveCards2()
    {

        Debug.Log("GiveCards2");

        int[] c;

        c = cDeal.cards12;

        int a = c[0];

        var go = GameObject.FindGameObjectWithTag(a.ToString());
        go.transform.localPosition = nulll;
        go.transform.parent = slots[4].transform;

        int a1 = c[1];
        var go1 = GameObject.FindGameObjectWithTag(a1.ToString());
        go1.transform.localPosition = nulll;
        go1.transform.parent = slots[5].transform;
                                                                          
        int a2 = c[2];                                                           //I know this doable someway else could you tell me how? :'D
        var go2 = GameObject.FindGameObjectWithTag(a2.ToString());
        go2.transform.localPosition = nulll;
        go2.transform.parent = slots[6].transform;

        int a3 = c[3];
        var go3 = GameObject.FindGameObjectWithTag(a3.ToString());
        go3.transform.localPosition = nulll;
        go3.transform.parent = slots[7].transform;

    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager_Master : MonoBehaviour {

    public delegate void GeneralEventHandler();
    public event GeneralEventHandler EventGameStart;

    public void CallEventGameStart()
    {
        EventGameStart();
    }
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class Cards_Deal : MonoBehaviour {

    int[] cards = Enumerable.Range(1, 32).ToArray();

    public float dealTime;

    public List<GameObject> players;

    GameManager_Master gmMaster;

    Player_Master pMaster1;
    Player_Master pMaster2;
    Player_Master pMaster3;
    Player_Master pMaster4;

    int[] cards1;
    int[] cards2;

    int[] cards3;
    int[] cards4;
    int[] cards5;
    int[] cards6;

    public int[] cards7;
    public int[] cards8;
    public int[] cards9;
    public int[] cards10;
    public int[] cards11;
    public int[] cards12;
    public int[] cards13;
    public int[] cards14;

    int dummy;

    void OnEnable () {
        Wait();
        dummy = 0;
        SetInitRefs();
        MixCards();
        gmMaster.EventGameStart += DealCards;
        gmMaster.EventGameStart += GameStartDebug;
        pMaster1.EventFirst4CardsOnHand += DealCards;
        pMaster1.EventAllCardsOnHand += DealCards;
    }

    private void OnDisable()
    {
        gmMaster.EventGameStart -= MixCards;
        gmMaster.EventGameStart -= DealCards;
        gmMaster.EventGameStart -= GameStartDebug;
        pMaster1.EventFirst4CardsOnHand -= DealCards;
        pMaster1.EventAllCardsOnHand -= DealCards;
    }

    void SplitArray(int[] array, out int[] firstArray, out int[] secondArray)
    {
        firstArray = array.Take(array.Length / 2).ToArray();
        secondArray = array.Skip(array.Length / 2).ToArray();
    }

    void Start()
    {
        WaitLonger();
        gmMaster.CallEventGameStart();
    }

    void MixCards()
    {
        shuffle(cards);
        SplitArray(cards, out cards1, out cards2);
        SplitArray(cards1, out cards3, out cards4);
        SplitArray(cards2, out cards5, out cards6);
        SplitArray(cards3, out cards7, out cards8);
        SplitArray(cards4, out cards9, out cards10);
        SplitArray(cards5, out cards11, out cards12);
        SplitArray(cards6, out cards13, out cards14);
    }

    void shuffle(int[] cards)
    {
        for (int t = 0; t < cards.Length; t++)
        {
            int tmp = cards[t];
            int r = Random.Range(t, cards.Length);
            cards[t] = cards[r];
            cards[r] = tmp;
        }
    }

    void SetInitRefs()
    {
        gmMaster = GetComponent<GameManager_Master>();
        pMaster1 = players[0].GetComponent<Player_Master>();
        pMaster2 = players[1].GetComponent<Player_Master>();
        pMaster3 = players[2].GetComponent<Player_Master>();
        pMaster4 = players[3].GetComponent<Player_Master>();
    }

    void Update () {
       
    }

    new IEnumerator DealTime()
    {
        yield return new WaitForSeconds(dealTime);
    }


    void DealCards()
    {
        if(dummy == 0)
        {
            Debug.Log(cards8[0] + " " + cards8[1]);
            pMaster1.CallEventFirst4CardsOnHand();
            //pMaster2.CallEventFirst4CardsOnHand();
            //pMaster3.CallEventFirst4CardsOnHand();
            //pMaster4.CallEventFirst4CardsOnHand();
            dummy++;
            Wait();
        }
        else if(dummy == 1)
        {
            DealTime();
            pMaster1.CallEventAllCardsOnHand();
            //pMaster2.CallEventAllCardsOnHand();
            //pMaster3.CallEventAllCardsOnHand();
            //pMaster4.CallEventAllCardsOnHand();
            dummy++;
            Wait();
        }
        else if(dummy == 2)
        {

            dummy = 0;
        }
        else
        {
            Debug.LogWarning("Error in Dealing Cards");
        }

       
    }

    void GameStartDebug()
    {
        Debug.Log("Game Started");
    }

    IEnumerator Wait()
    {
        yield return new WaitForSeconds(0.5f);
    }

    IEnumerator WaitLonger()
    {
        yield return new WaitForSeconds(1);
    }
}

Why do you do this?

IEnumerator Wait()
    {
        yield return new WaitForSeconds(0.5f);
    }
    IEnumerator WaitLonger()
    {
        yield return new WaitForSeconds(1);
    }

Why not:

IEnumerator Wait(float WaitTime)
    {
        yield return new WaitForSeconds(WaitTime);
    }

You have so much repeated code, it’s pretty insane. I think at this point you’re trying to do more than you’re capable of. Learn the tools needed before you try more complicated things!

Did you look in the Profiler? I’m guessing that you’re calling many of those Wait coroutines on start. Try removing (or Debug.Log them) to see what’s taking so long.