[solved]Help , getting overflowException

i am getting an error in my counsel - OverflowException: Number overflow.
Grid.CreateGrid() (at Assets/Grid.cs:35)
and i can’t figure out why
any help would be appreciated

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

public class Grid : MonoBehaviour
{
    //
    public LayerMask unwalkableMask;

    //size grid will cover
    public Vector2 gridWorldSize;

    //defines how much space each node covers
    public float nodeRadius;

    //array for nodes
    Node[,] grid;

    //
    float nodeDiameter;
    //
    int gridSizeX;
    int gridSizeY;

    void Start()
    {
        nodeDiameter = nodeDiameter * 2;
        gridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter);
        gridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);
        CreateGrid ();
    }

    void CreateGrid()
    {
        grid = new Node[gridSizeX, gridSizeY];
        Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int y = 0; x < gridSizeY; y++)
            {
                Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
                //collision chec
                bool walkable = !(Physics.CheckSphere(worldPoint,nodeRadius,unwalkableMask));
                grid [x, y] = new Node (walkable, worldPoint);
            }
        }
    }

    void OnDrawGizmos()
    {
        Gizmos.DrawWireCube (transform.position, new Vector3 (gridWorldSize.x, 1, gridWorldSize.y));

        if (grid != null)
        {
            foreach(Node n in grid)
            {
                Gizmos.color = (n.walkable) ? Color.white : Color.red;
                Gizmos.DrawCube (n.worldPosition, Vector3.one * (nodeDiameter - .1f));
            }
        }
    }
}

solved

The size of the array exceeds Int32 size.

How was the problem solved?

In one of my for loops in “create grid” I had an “x” instead of a “y”

I have the same code but the error is still there!
Could someone help?

looks like you have your for loops as “(int x -0;” and (int y -0;" instead of “=”
can’t really tell because its a picture…are you aware of copy and paste

is it solved

can you tell me what exactly did you change

Please don’t necro-post. If you have a new question, make a new post. It’s FREE!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

  • Do not TALK about code without posting it.
  • Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
  • Do NOT post screenshots of code.
  • Do NOT post photographs of code.
  • Do NOT attach entire scripts to your post.
  • ONLY post the relevant code, and then refer to it in your discussion.