playMaker

Author Topic: NullReferenceException: Object reference not set to an instance of an object  (Read 1089 times)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
I'm having a problem with the trigger error when in build mode. In the editor, everything is fine.

Before this project, I also have the same issue with the trigger collider throwing error message in build mode only.

This one is basically calling a method from other game object script when the thing is triggered with the "Player" tag. I'm sure had already connected all of the references in Start().

Does anyone know how to fix this? Been looking around but can't seem to find the exact same problem as mine, even though it's the same error message.

Quote
Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at CollectibleItem.OnTriggerEnter2D (UnityEngine.Collider2D collision) [0x00011] in C:\Users\Billy\Unity_Projects\Jump and Run Project\Assets\_Re\Scripts\CollectibleItem.cs:30
 
(Filename: C:/Users/Billy/Unity_Projects/Jump and Run Project/Assets/_Re/Scripts/CollectibleItem.cs Line: 30)

Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at GameManager.GameOver () [0x00001] in C:\Users\Billy\Unity_Projects\Jump and Run Project\Assets\_Re\Scripts\GameManager.cs:42
  at EnemyObstacle.OnTriggerEnter2D (UnityEngine.Collider2D collision) [0x0001d] in C:\Users\Billy\Unity_Projects\Jump and Run Project\Assets\_Re\Scripts\EnemyObstacle.cs:28
 
(Filename: C:/Users/Billy/Unity_Projects/Jump and Run Project/Assets/_Re/Scripts/GameManager.cs Line: 42)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
really really stuck here, already tweaking the code all day long and it still resulting in the same error no matter what.


EDIT:
after changing from
      gameManager = FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
to
      gameManager = FindObjectOfType<GameManager>();
it works somehow.

But why? I have this kind of error before when fully using PM in my previous project. Are we basically not allowed to use 'get component'? It will work fine in Editor but not in Build mode.
« Last Edit: March 18, 2020, 12:33:18 PM by rechronicle »