NullReferenceException in WebGL build but not in Editor

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.

NullReferenceException: Object reference not set to an instance of an object.
UnityLoader.js:4   at VisionBreak.Sunsear.Boss.Doppelganger.Initialize (VisionBreak.Sunsear.PlayerCore.Player player) [0x00000] in <00000000000000000000000000000000>:0
UnityLoader.js:4   at VisionBreak.Sunsear.Boss.DoppelgangerSpawner.Spawn () [0x00000] in <00000000000000000000000000000000>:0
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:

public void Initialize(Player player) {
            if (player == null) {
                Debug.LogWarning("Doppelganger@Initilize: Player has not been assigned");
                return;
            }
            this.player = player;
            shieldCount = this.player.shieldCount;
            laserCount = this.player.megaLaserCount;
            CopyPlayerArsenal();
            Debug.Log("Start doppelganger battle");
          
            fightStarted = true;
            StartCoroutine(Battle());
        }

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():

void Update()
        {
            if (!isSpawned && !player) {
                GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
                player = playerObj.GetComponent<PlayerCore.Player>();
                Debug.Log("Retrieving Player component", playerObj);
            }
            . . .
        }

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?

How was this fixed? Do you have a link?

Same question! :slight_smile: