NullReferenceException: Object reference not set to an instance of an object

Lecture: “Unit Movement”
Reason (that i think):

Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, maxDistanceForRayCast, NavMesh.AllAreas)

in the above line i used the new input system code and that caused the issue.

!Physics.Raycast(mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue()), out RaycastHit hit, maxDistanceForRayCast, NavMesh.AllAreas)

please guide.

issue resolved, sorry for disturbance.

it was due to main camera did not had the “maincamera” tag.

1 Like

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

Privacy & Terms