Level Grid - Grid size being set in Awake?

Great course and I’m learning so much.

I just have a quick question and apologize if it has been asked before.

The size of the Grid is set in the LevelGrid.cs class in Awake. Should it just ignore this for now as it is touched on later on in the course?

I was also curious as to the reason why it was set here rather than the GridSystem struct instead.

    private void Awake()
    {
        // Set the instance
        if (Instance != null)
        {
            Debug.LogError("There's more than one Level Grid! " + transform + " - " + Instance);
            Destroy(gameObject);
            return;
        }
        Instance = this;

        //TODO get rid of Magic Numbers?
        gridSystem = new GridSystem(10, 10, 2f);
        gridSystem.CreateDebugObjects(gridDebugObjectPrefab);
    }

We don’t have a way to serialize values in the GridSystem, as it’s not a MonoBehaviour attached to a GameObject, it’s a class that we spawn when the game starts. This means that the gridSystem needs to be told the dimensions of the game when it is spawned in. You’ll be able to serialize the dimenssions in the LevelGrid class.

I also allows us to reuse the GridSystem in other games where other grid sizes are required without having to change the GridSystem each time

1 Like

Its all about clean code. OFC. GridSystem does one thing and done thing only.

Thanks, guys I can see the logic now.

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

Privacy & Terms