Pathfinder Script is running before your Tile Script? Fix inside!

So i had an issue with my pathfinder script was executing before it even got to my Tile script. This cause the Pathfinder to just go where ever it wanted as the isWalkable flag was never set. After a lot of debugging I found that the BreadthSearch executed before the tile script changed the flag.

I was racking my head trying to find an answer. Moving blocks of code to Awake vs Start in Tile, (which broke things since Grid Manager needed to execute first because it never created the grid first.)

Below is part of my Tile script at the Awake function. I removed anything in the start function.

Tile.cs Awake code.

void Awake()

    gridManager = FindObjectOfType();

    if (gridManager != null)
        coordinates = gridManager.GetCoordinatesFromPosition(transform.position);

        if (!isPlaceable)

            /*if (grid.ContainsKey(coordinates))
                Debug.Log($"Blocking node, tilecs {grid[coordinates].isWalkable} at {coordinates}");


I then went into Script Execution order ( edit → project settings → Script execution order) and at the bottom added, the Grid Manager followed by the Tile script.

This was from constant debugging and trying to find out what executed first. Nothing else changed except that awake method. (this is from after the blocking nodes video, so any future code changes in that course are not in this code.)

Hi TheSpaceBro,

Thanks a lot for sharing your solution.

The script execution order is often a problem because Unity methods of the same name get executed in a random order. Most problems can be solved by using Awake() and Start() (or other Unity methods). If that does not solve the problem, defining the Script Execution Order is the right way to go. :slight_smile:

1 Like

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

Privacy & Terms