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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13049
    Haydn V
    Participant
    Helpful?
    Up
    0
    ::

    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));
    
            }
        }
    }
    #13050
    Haydn V
    Participant
    #13060
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: