Forum begins after the advertisement:
[part 5]NullReferenceException: Object reference not set to an instance of an ob
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [part 5]NullReferenceException: Object reference not set to an instance of an ob
- This topic has 2 replies, 2 voices, and was last updated 1 year ago by Terence.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
January 7, 2024 at 6:27 pm #13049::
there is an error that happens when my player touches the scene transition in makes the player not enter the next scene the error points out the NullReferenceException: Object reference not set to an instance of an object SceneTransition.OnTriggerEnter2D (UnityEngine.Collider2D _other) (at Assets/scripts/SceneTransition.cs:37)
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneTransition : MonoBehaviour { [SerializeField] private string transitionTo; [SerializeField] private Transform startPoint; [SerializeField] private Vector2 exitDirection; [SerializeField] private float exitTime; private void Start() { if(transitionTo == GameManager.instance.transitionFromScene) { PlayerController.instance.transform.position = startPoint.position; StartCoroutine(PlayerController.instance.WalkIntoNewScnene(exitDirection, exitTime)); } StartCoroutine(UiManager.instance.sceneFader.fade(ScreenFader.fadeDirection.Out)); } private void OnTriggerEnter2D(Collider2D _other) { if (_other.CompareTag("Player")) { GameManager.instance.transitionFromScene = SceneManager.GetActiveScene().name; PlayerController.instance.pState.transition = true; StartCoroutine(UiManager.instance.sceneFader.FadeAndLoadScene(ScreenFader.fadeDirection.In, transitionTo)); } } }
January 7, 2024 at 6:29 pm #13050January 8, 2024 at 4:44 pm #13060::Hi Haydn,
The error should be here:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneTransition : MonoBehaviour { [SerializeField] private string transitionTo; [SerializeField] private Transform startPoint; [SerializeField] private Vector2 exitDirection; [SerializeField] private float exitTime; private void Start() { if(transitionTo == GameManager.instance.transitionFromScene) { PlayerController.instance.transform.position = startPoint.position; StartCoroutine(PlayerController.instance.WalkIntoNewScnene(exitDirection, exitTime)); } StartCoroutine(UiManager.instance.sceneFader.fade(ScreenFader.fadeDirection.Out)); } private void OnTriggerEnter2D(Collider2D _other) { if (_other.CompareTag("Player")) { GameManager.instance.transitionFromScene = SceneManager.GetActiveScene().name; PlayerController.instance.pState.transition = true; StartCoroutine(UiManager.instance.sceneFader.FadeAndLoadScene(ScreenFader.fadeDirection.In, transitionTo)); Debug.Log(UiManager.instance); Debug.Log(UiManager.instance.sceneFader); } } }
Can you put the lines highlighted in green above and show me the Console output? And show me your Inspector for the UIManager as well.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Advertisement below: