Game Breaks after this lecture

Unity Editor breaks when i press play after appyling the grid size 4 x 3 to the GridManager Object.
GridManager GameObject has a GridManager script.

Thanks

Hi,

Which version of Unity do you use?

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Maybe there is an endless loop in your script.

If there isn’t any, do you happen to use a laptop? If so, make sure the power chord is plugged in. Otherwise, your operating system might be running the power saving mode, which slows everything down.


See also:

Thanks for the prompt reply!
I am using version 2022.1.16f1
I am currently using a desktop.

My GridManager script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class GridManager : MonoBehaviour

{

    [SerializeField] Vector2Int gridSize;

    Dictionary<Vector2Int, Node> grid = new Dictionary<Vector2Int, Node>();

    void Awake()

    {

        CreateGrid();

    }

    void CreateGrid()

    {

        for(int x = 0; x < gridSize.x; x++)

        {

            for(int y = 0; x < gridSize.y; y++)

            {

                Vector2Int coordinates = new Vector2Int (x,y);

                grid.Add(coordinates, new Node(coordinates, true));

                Debug.Log(grid[coordinates].coordinates +  " = " + grid[coordinates].isWalkable);

            }

        }

    }

}

I cannot see any issue in your code. What exactly do you mean by “Unity Editor breaks”? Maybe I misunderstood your problem.

Unity freezes up and I can’t do anything when I press play with that code on the game object called GridManager

Mini Challenge Time - Spot the typo

x < gridSize.y should be y < gridSize.y. This is a recipe for an endless loop

2 Likes

Ah that’s why!
Thanks
I’m going to try that in a bit
Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms