A part of my game is not working in build, but working fine in the editor.

In the editor, the player can hit a loading zone to switch to another scene, which works completely fine untill I build it. Usually the screen would fade and then the new scene would load in but in the build, nothing happens when you hit the trigger collider loading zone. I have no idea why this happens so I checked the player.log.txt which says:

NullReferenceException: Object reference not set to an instance of an object
at LoadNewArea.OnTriggerEnter2D (UnityEngine.Collider2D other) [0x00037] in <6c6cea2253834be4b16b82ec92feb9c8>:0

(Filename: <6c6cea2253834be4b16b82ec92feb9c8> Line: 0)

This is the script attached to the loading zone:

public class LoadNewArea : MonoBehaviour
public Object newScene;

public static float playerX, playerY; // player y and x of when the new area box is hit.

public int LoadUDLR; 

private void OnTriggerEnter2D(Collider2D other)
    if(other.gameObject.name == "Player")
        playerX = FindObjectOfType<PlayerController>().transform.position.x;
        playerY = FindObjectOfType<PlayerController>().transform.position.y;
        Debug.Log("Moving to " + newScene.name);


and this is the script for loading new scenes (completely copied from brackeys lol):

public class LevelLoader : MonoBehaviour
public Animator transition;

public void LoadScene(string sceneName)

IEnumerator LoadLevel(string levelName)

    yield return new WaitForSeconds(0.5f);


// https://www.youtube.com/watch?v=CE9VOZivb3I


I have obviously checked in the editor to see if I have correctly set all references in the inspector. Please ask me if you need any more information or answer this if you can. I know there are other questions like this already, but I feel that these issues have different solutions based on the context. Also sorry for the bad formatting in the question, I don’t really know how to do it correctly. Thanks!

I won’t get into too much detail because I don’t know if anyone even read this but loading scenes using the ‘Object’ variable doesn’t work in builds. You instead have to use strings which is annoying and less convenient but oh well atleast it works.