Specific class unable to access static variable

Hello, I’m trying to generate a background, but the class that generates the background is unable to see how big the map is: the static variable stored in the class GameManage. I can access this variable from all other classes, and in all other classes it is correct, but the background generator for some reason thinks that it is always 0. Does anyone have any idea what’s going on?

public void Spawn()
{
    int xMaxMin = Mathf.Round(GameManage.maxSize * GameManage.aspectRatio) + buffer;
    int yMaxMin = GameManage.maxSize + buffer;

    float xCoord = -xMaxMin;
    float yCoord = -yMaxMin;

    for (int i = -xMaxMin; i < xMaxMin; i ++)
    {
        if (xCoord > xMaxMin) break;
        for (int j = -yMaxMin; j < yMaxMin; j ++)
        {
            if (yCoord > yMaxMin) break;

            Instantiate(gameObject).transform.position = new Vector3(xCoord, yCoord, 0);
            yCoord += size;
        }
        xCoord += size;
        yCoord = -yMaxMin;
    }

That’s impossible. Are you sure that you do not have multiple classes named “GameManage” in different namespaces? Where and when do you assign the static values? Do you change them anywhere in your code? Have you actually tried logging the value inside your method?

Debug.Log("Spawn() ==> GameManage.maxSize = " + GameManage.maxSize, gameObject);
Debug.Log("Spawn() ==> GameManage.aspectRatio = " + GameManage.aspectRatio, gameObject);

Try adding those to the beginning of your Spawn method.

Note that this line:

Instantiate(gameObject)

looks really strange. Are you sure you want the object this script is attached to to duplicate itself? That means each of those objects will also have this script attached. Also Instantiate has an overload that allows you to specify the location and rotation directly. That would be more performant.