0

I got an error "NullReferenceException: Object reference not set to an instance of an object. PlayerCollision.OnCollisionEnter (UnityEngine.Collision collisionInfo)

(at Assets/Scripts/PlayerCollision.cs:15) "
enter image description here

I tried to make a script when I enter collision ill respawn but it works only on the first try but it don't work on the second try.

KiynL
  • 4,097
  • 2
  • 16
  • 34
  • As is seems, the problem is on line 15, that is probably because the is couldn't find "GameManager" – amitklein Feb 10 '23 at 19:33
  • 1
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – BugFinder Feb 10 '23 at 20:36

1 Answers1

0

oh for some reason in the build settings i got checked level1 then i unchecked it and it does not have any error now but thanks

  • Your GameManager seems to be only initialized in one scene (presumably level0). You could introduce an Prefab of the GameManager and make it an [Singleton](https://stackoverflow.com/questions/35890932/unity-game-manager-script-works-only-one-time/35891919#35891919) – Valerij Dobler Feb 16 '23 at 08:47