Answer the question
In order to leave comments, you need to log in
NullReferenceException: Object reference not set to an instance of an object when looking up an object. What to do?
Throws the error "NullReferenceException: Object reference not set to an instance of an object sceneMan.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/sceneMan.cs:14)" when I try to find an empty object with a tag or title.
Here is the script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class sceneMan : MonoBehaviour
{
public bool nStory;
public int id;
private void OnTriggerEnter2D(Collider2D collision)
{
SceneManager.LoadScene(int.Parse(name));
if (nStory)
{
Debug.Log("ppos"+id);
Debug.Log(GameObject.Find("Player").name);
Debug.Log(GameObject.FindGameObjectWithTag("ppos").name);
GameObject.Find("Player").transform.localPosition = GameObject.Find("ppos" + id).transform.localPosition;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question