Field ' ' is naver assigned to, and will always have its default value null

Hi everyone. I have go a warning but it converted error when game is playing. At the console 1-number line is being pointed. And the information at this line goes to 2-number line us and it goes to 3 but ı have defined everything. I could not understand where is the problem. Besides at game, the error is “NullReferenceException: Object reference not set to an instance of an object” . Thanks ahead.

            foreach (SnakeBodyPart snakeBodyPart in snakeBodyPartList)
            {

                Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition();   [B] 1[/B]

                if (gridPosition == snakeBodyPartGridPosition)
                {
                    Debug.Log("death");
                }
            }
    private class SnakeBodyPart
    {
        private SnakeMovePosition snakeMovePosition;   [B]2[/B]

        private Transform transform;
        public SnakeBodyPart(int bodyIndex)
        {
            GameObject snakeBodyGameObject = new GameObject("SnakeBody", typeof(SpriteRenderer));

            snakeBodyGameObject.GetComponent<SpriteRenderer>().sprite = GameAssets.i.snakeBodySprite;

            snakeBodyGameObject.GetComponent<SpriteRenderer>().sortingOrder = -bodyIndex;

            transform = snakeBodyGameObject.transform;
        }

        public void SetSnakeMovePosition(SnakeMovePosition snakeMovePosition)
        {
            this.snakeMovePosition = snakeMovePosition;

            transform.position = new Vector3(snakeMovePosition.GetGridPosition().x, snakeMovePosition.GetGridPosition().y);
        }

        public Vector2Int GetGridPosition()     [B]3[/B]
        {
            return snakeMovePosition.GetGridPosition();
        }
    }


    private class SnakeMovePosition
    {
        private Vector2Int gridPosition;

        public SnakeMovePosition(Vector2Int gridPosition)
        {
            this.gridPosition = gridPosition;
        }

        public Vector2Int GetGridPosition()     [B] [/B]
        {
            return gridPosition;
        }
    }

That error usually means you forgot to assign something in the inspector. I would check every variable in the inspector before you hit play and then check again after you hit play to make sure everything is being assigned, regardless of public or private.

Please post the entire script and the entire error message.
The error will point to the line number in the script that it’s occurring in.

As mentioned above, a NullReferenceException means you declared an object variable and did not assign a reference to it.