Search Unity

Resolved NullReferenceException in WebGL build but not in Editor

Discussion in 'Web' started by cyangamer, Aug 3, 2020.

  1. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    Update: This has been resolved. The orders have child transforms in the hierarchy can sometimes be switched around when building. Weird quirk, but easily fixable.

    See original post below:


    Unity Version: 2018.4.25f1
    Development Build: true
    Strip Engine Code: I used both Low and None/[unchecked] and the result was the same.
    Exception Logging: Full

    Here's what gets returned at the end of my level where a boss should be appearing.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object.
    2. UnityLoader.js:4   at VisionBreak.Sunsear.Boss.Doppelganger.Initialize (VisionBreak.Sunsear.PlayerCore.Player player) [0x00000] in <00000000000000000000000000000000>:0
    3. UnityLoader.js:4   at VisionBreak.Sunsear.Boss.DoppelgangerSpawner.Spawn () [0x00000] in <00000000000000000000000000000000>:0
    4. UnityLoader.js:4   at VisionBreak.Sunsear.Boss.DoppelgangerSpawner.Update () [0x00000] in <00000000000000000000000000000000>:0
    Like I said, this boss appears as normal without any errors in the Editor. Here's the entire Initialize() method:

    Code (CSharp):
    1. public void Initialize(Player player) {
    2.             if (player == null) {
    3.                 Debug.LogWarning("Doppelganger@Initilize: Player has not been assigned");
    4.                 return;
    5.             }
    6.             this.player = player;
    7.             shieldCount = this.player.shieldCount;
    8.             laserCount = this.player.megaLaserCount;
    9.             CopyPlayerArsenal();
    10.             Debug.Log("Start doppelganger battle");
    11.          
    12.             fightStarted = true;
    13.             StartCoroutine(Battle());
    14.         }
    The "Doppelganger@Initilize" warning log shows up in the console.

    Originally the Player component was retrieved by another script in its Start function. I copied it to the Update() function to see if that made a difference and it didn't. Here's is the code that calls Initialize():
    Code (CSharp):
    1. void Update()
    2.         {
    3.             if (!isSpawned && !player) {
    4.                 GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
    5.                 player = playerObj.GetComponent<PlayerCore.Player>();
    6.                 Debug.Log("Retrieving Player component", playerObj);
    7.             }
    8.             . . .
    9.         }
    Instead it keeps failing to get the component even those I see that it's attached correctly and it runs fine in the Editor.

    Any ideas on where the inconsistency is coming from?
     
    Last edited: Aug 4, 2020
  2. gumball373

    gumball373

    Joined:
    Apr 5, 2021
    Posts:
    1
    How was this fixed? Do you have a link?
     
  3. StevenBeyen

    StevenBeyen

    Joined:
    Dec 23, 2019
    Posts:
    1
    Same question! :)