Can't place towers after a few seconds

When start the game, after a few seconds I start getting this error message whenever I try to place a tower:

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at <cb77d76f0e674d3da5f8c94addc0e0a6>:0)
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at <cb77d76f0e674d3da5f8c94addc0e0a6>:0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at <cb77d76f0e674d3da5f8c94addc0e0a6>:0)
TowerFactory.InstansiatieNewTower (Waypoint baseWaypoint) (at Assets/Scripts/TowerFactory.cs:27)
TowerFactory.AddTower (Waypoint baseWaypoint) (at Assets/Scripts/TowerFactory.cs:16)
Waypoint.OnMouseOver () (at Assets/Scripts/Waypoint.cs:36)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

If I try to place a tower in the first ~7 seconds, it works. If I try to place one after this I get the error message above.

Hi Erick,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

Also make sure that the field does not reference a game object from your Hierarchy. If that game object gets destroyed during runtime, you’ll get a NullReferenceException as well.

It seems to me that some of the waypoints don’t have explored from values set, this seems to be an issue with the pathfinding so I’ll try to copy Ben’s copy of the script and replace mine.

It’s just a guess but stop your game, select all Waypoints in the Hierarchy and make sure that “IsExplored” is not set to true anywhere.

However, I currently don’t know what the pathfinding algorithm should have to do with towers that cannot be placed anymore. Did you already solved the problem with the NullReferenceException or did you figure out more?

1 Like

I think that Ben fixed it after a few episodes, I copied his scripts so it was either that or he fixed it.

Does that mean the problem is solved? :slight_smile:


See also:

Yeah, probably. I’ll mark it as solved.

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

Privacy & Terms