After following the Script Execution Order lesson (and going back over the previous three lessons to see if there were any coding errors) I can only get my enemy ram objects to fly across the screen diagonally.
Are there any error messages in your console during runtime? Maybe a NullReferenceException error?
No. I’m not getting any runtime errors after changing the script execution order to include GridManager and Pathfinder (in that order).
Prior to adding them I had two errors:
NullReferenceException: Object reference not set to an instance of an object
Pathfinder.GetNewPath () (at Assets/Pathfinding/Pathfinder.cs:42)
EnemyMover.RecalculatePath () (at Assets/Enemy/EnemyMover.cs:33)
EnemyMover.OnEnable () (at Assets/Enemy/EnemyMover.cs:18)
ObjectPool:PopulatePool() (at Assets/Enemy/ObjectPool.cs:29)
ObjectPool:Awake() (at Assets/Enemy/ObjectPool.cs:15)
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <9577ac7a62ef43179789031239ba8798>:0)
Pathfinder.Awake () (at Assets/Pathfinding/Pathfinder.cs:30)
When I run the game (regardless of script execution order) I get the same behavior from the enemy object. It just flies diagonally from the startCoordinates to the destinationCoordinates.
Could you please share a screenshot of the script execution order list?
Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe the ObjectPool object executes its code before the GridManager and the Pathfinder.
Added Debug.Logs to the Awake methods in Pathfinder, GridManager, and ObjectPool. They all show messages with the same timestamp.
I tried to add ObjectPool underneath Pathfinder in the script execution order as a quick fix but it did not change anything.
Found the solution.
In my Pathfinding script under List BuildPath() I had path.Add(currentSearchNode) in two places.
After changing them to path.Add(searchNode) the enemies started behaving correctly.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.