- Home /
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 :0
(Filename: 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;
FindObjectOfType<LevelLoader>().LoadScene(newScene.name);
FindObjectOfType<PlayerController>().GetStartPoint(LoadUDLR);
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)
{
StartCoroutine(LoadLevel(sceneName));
}
IEnumerator LoadLevel(string levelName)
{
transition.SetTrigger("FadeStart");
yield return new WaitForSeconds(0.5f);
SceneManager.LoadScene(levelName);
}
// 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!
Answer by KevinDover · Apr 14, 2020 at 06:44 AM
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.
Your answer
Follow this Question
Related Questions
Android APK Build Failing "Execution failed for task ':launcher:checkReleaseDuplicateClasses'." 5 Answers
Gradle Build Error 1 Answer
Making a unity build fails every attempt. 0 Answers
Can't build my android project 1 Answer
LOTS of build errros 0 Answers