Errors not fixed after changing the script execution order

Even after I changed the script execution order and moved the two lines:

            startNode.isWalkable = true;
            destinationNode.isWalkable = true;

Into BreadthFirstSearch, the errors persist and the path isn’t generated. Could anyone help me with this?

Hi Erick,

Have you already rewatched the video at least one more time? If so, could you please share more information on what you did and have in your project?

I’ve re-watched the video, however my script seem to be the same. I will make sure they are by copying their scripts from gitlab.

I have now completely copied the script from GitLab and they still don’t work, I am getting these errors (in order of how they appeared in the console):

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
Pathfinder.Awake () (at Assets/Pathfinding/Pathfinder.cs:31)
NullReferenceException: Object reference not set to an instance of an object
Pathfinder.BreadthFirstSearch () (at Assets/Pathfinding/Pathfinder.cs:75)
Pathfinder.GetNewPath () (at Assets/Pathfinding/Pathfinder.cs:43)
EnemyMover.FindPath () (at Assets/Enemy/EnemyMover.cs:33)
EnemyMover.OnEnable () (at Assets/Enemy/EnemyMover.cs:18)
UnityEngine.Object:Instantiate(GameObject, Transform)
ObjectPool:PopulatePool(GameObject) (at Assets/Enemy/ObjectPool.cs:29)
ObjectPool:Awake() (at Assets/Enemy/ObjectPool.cs:14)

(This second one appeared multiple times)

I also can’t place towers, however when I click the block becomes not walkable, noted by the colour change of the coordinate label.

Could you please upload your project to GitHub without the Temp and Library folder and share a link to the public repository here? I’d like to take a look into this.

Here is a tutorial video by Brackeys:

Here’s the link:

Thank you. I’ve downloaded and tested your project in Unity 2021.1.4f1. When I “played” the game scene, the first thing I noticed/heard is my GPU singing. This indicates that there might be a huge problem in your game. Did you do anything special in your game, for example, with shaders? Or did you change the quality settings?

The second thing I noticed was that no enemies got spawned. When I placed the tower, I got this error message:


Unfortunately, I was not able to recreate any of the problems you got. Maybe I did something wrong. Would you mind telling me what I am supposed to do to get the same results as you?

I made the lighting realtime using the lighting settings.

I don’t really do anything other than click play, did you not get a error about the given key not being available in the dictionary?

Unfortunately not. That’s why I asked. :confused:

No enemies got spawned in my case. That’s probably the reason why I didn’t get the NullReferenceException and the KeyNotFoundException.

Updated Sun Apr 25 2021 16:08

I have investigated the problem a bit further. The pool size of the ObjectPool component of the ObjectPool game object was 0, so I set it to 1.


Now I’m getting two error messages:

Then I checked the script execution order. There is no ObjectPool or GridManager object in the list.


I added GridManager and ObjectPool to the list.


A Debug.Log in the EnemyMover revealed that the List object existed, but the List object did not contain any elements.

    private void ReturnToStart()
        Debug.Log("path: " + path);
        Debug.Log("path.Count: " + path.Count);
        transform.position = path[0].transform.position;

I checked where elements get added to the list.

        foreach (Transform child in parent.transform)
            Waypoint waypoint = child.GetComponent<Waypoint >();

            if (waypoint != null)

According to this piece of code, the child gets added only if a Waypoint component is attached to it. There is no Waypoint component attached to any of the children of the Path game object.


After I had added the Waypoint component, the enemy started to move, and no errors got thrown anymore.

Hmm, yeah seems I hadn’t committed and pushed since I did that lecture, I’ll check that out later when I get home.

I pushed my changes, however adding the waypoint script did nothing for me and also I have now found that it should not still be in the game at this point. I have tried to delete it however that has not seemed to have worked. I will try to get all the scripts copied across and then push again.

I tried some more copying script but it still hasn’t worked, I’ve pushed my commits to GitLab so you should be able to try the broken copy now :slight_smile:

Now I’m getting this error message:


It refers to this line:

path = pathfinder.GetNewPath();

In the Awake method, the Pathfinder object should get assigned to pathfinder:

pathfinder = FindObjectOfType<Pathfinder>();

I was not able to find a Pathfinder component anywhere in the scene. And the EnemyMover object didn’t find any either, hence the NullReferenceException. Gary attached the Pathfinder component to the ObjectPool game object.

Edit: Thanks for reopening the thread
Original reply:
Sorry it’s been a busy few days. Hmmm, it’s strange that there was no pathfinder script on the ObjectPool object. I’ve attached it however I still get the same errors.

Maybe it is a good idea to rewatch the videos. There are too many things missing here and there, and it is probably way faster to simply comparing your project to Gary’s while rewatching the videos instead of individually tracking each single error and fixing it when new errors are expected to pop up whenever you solve a problem.

Ok, I’ll do that.

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

Privacy & Terms