UpdateGridVisual() priority issues?

Trying to figure out why, but in formatting my code exactly as shown in the lesson, having my UpdateGridVisual(); in the Start function leads to NullReferenceExeption, unless I lower GridSystemVisual’s priority. Is this something that was mentioned and I missed, or something that is just happening to me?

private void Start()
    {
        gridSystemVisualSingleArray = new GridSystemVisualSingle[
            LevelGrid.Instance.GetWidth(),
            LevelGrid.Instance.GetHeight()
            ];

        for (int x = 0; x < LevelGrid.Instance.GetWidth(); x++)
        {
            for (int z = 0; z < LevelGrid.Instance.GetHeight(); z++)
            {
                GridPosition gridPosition = new GridPosition(x, z);
                Transform gridSystemVisualSingleTransform =
                    Instantiate(gridSystemVisualSinglePrefab, LevelGrid.Instance.GetWorldPosition(gridPosition), Quaternion.identity);

                gridSystemVisualSingleArray[x, z] = gridSystemVisualSingleTransform.GetComponent<GridSystemVisualSingle>();
            }
        }

        UnitActionSystem.Instance.OnSelectedActionChanged += UnitActionSystem_OnSelectedActionChanged;
        LevelGrid.Instance.OnAnyUnitMovedGridPosition += UnitActionSystem_OnAnyUnitMovedGridPosition;

        UpdateGridVisual();
    }

Lowered Priority:

Regular Priority:

Hugo mentions in several of the videos setting script execution order. Unfortunately, these settings appear to have been excluded from the course repo commit (perhaps they got caught up in the GitIgnore).
The GridSystemVisual depends on the LevelGrid and UnitActionSystem, so these to components must run before the GridSystemVisual.

1 Like

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

Privacy & Terms