Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 06, 2016 at 07:28 AM by El-Deiablo for the following reason:

Other

avatar image
0
Question by El-Deiablo · Jul 03, 2016 at 05:16 AM · scenenullreferenceexceptionfade

Scene Fader - Please Help!

This is the first time I have had this issue and I have been working on this project for 6 months and am almost done. I have seen several others with this issue, but no one has answered. Below you will find my code as well as photos showing my hiearchy and inspector panel. I have gone through several tutorials (Here's a link to the most recent that caused this same error - https://www.youtube.com/watch?v=jbuNElqqO2M), debugged, and scoured the internet for a solution, but continue to get this error (Lines 22 and 34 located in Code 1 - SceneFader.instance.FadeIn("Title Menu"); / SceneFader.instance.FadeIn ("Gameplay");):

NullReferenceException: Object reference not set to an instance of an object ChangeSceneManager.MainMenu () (at Assets/Scripts/Mangers/ChangeSceneManager.cs:25) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) UnityEngine.Events.UnityEvent.Invoke () UnityEngine.UI.Button.Press () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

Here's my code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine .SceneManagement ;
 using UnityEngine .UI;
 
 public class ChangeSceneManager : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
 
     }
 
     public void MainMenu(){
 
         //SceneManager.LoadScene ("Title Menu");
         //SceneFader.instance.LoadLevel("Title Menu");
         SceneFader.instance.FadeIn("Title Menu");
 
     }
 
     public void HowToPlay(){
 
         SceneManager.LoadScene ("How To Play Scene");
         //SceneFader.instance.LoadLevel("How To Play Scene");
     }
 
     public void Play(){
 
         SceneFader.instance.FadeIn ("Gameplay");
         //SceneManager.LoadScene ("Gameplay");
     }
 }

Code 2:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 
 public class SceneFader : MonoBehaviour {
 
     public static SceneFader instance;
 
     [SerializeField]
     private GameObject fadeCanvas;
 
     [SerializeField]
     private Animator fadeAnim;
 
     void Awake(){
 
         MakeASingleInstance ();
 
     }
 
     void MakeASingleInstance(){
 
         if (instance != null) {
 
             Destroy (gameObject);
 
         } else {
 
             instance = this;
             DontDestroyOnLoad (gameObject);
 
         }
 
     }
 
     IEnumerator FadeInAnimate (string levelName){
 
         fadeCanvas.SetActive (true);
         fadeAnim.Play ("FadeIn");
         yield return new WaitForSeconds (1f);
         SceneManager.LoadScene (levelName);
         FadeOut ();
 
     }
         
     IEnumerator FadeOutAnimate(){
 
         fadeAnim.Play ("FadeOut");
         yield return new WaitForSeconds (0.7f);
         fadeCanvas.SetActive (false);
 
     }
 
     public void FadeIn(string levelName){
 
         StartCoroutine (FadeInAnimate (levelName));
 
     }
 
     public void FadeOut(){
 
         StartCoroutine (FadeOutAnimate ());
 
     }
 }

I have been working on this scenefader for days now and continue to run into this issue. I am so close to finishing my game and want to add some polish to it. I would really appreciate some help.

Here are some screen shots of the gameobject as well:

screen-shot-2016-07-03-at-71333-am.png (32.1 kB)
screen-shot-2016-07-03-at-71401-am.png (17.1 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Haerius · Jul 05, 2016 at 01:29 AM 0
Share

line 25 of your ChangeScene$$anonymous$$anager that you posted here, is empty. I suspect you changed the formatting.. could you specify to which line it takes you if you click on the error message?

avatar image El-Deiablo Haerius · Jul 05, 2016 at 02:19 AM 0
Share

Lines 22 and 34 located in Code 1 - SceneFader.instance.FadeIn("Title $$anonymous$$enu"); / SceneFader.instance.FadeIn ("Gameplay");

1 Reply

  • Sort: 
avatar image
0

Answer by Glurth · Jul 05, 2016 at 11:49 PM

I would guess the object you have the SceneFader behavior attached to is disabled or corrupted somehow: preventing it's awake function from being called. This would leave the "instance" member variable uninitialized, and therefore equal to NULL.

The specific error you are getting means that you are trying to access a member of the "instance" variable, but since it's null (not instantiated), it can't store members yet.

P.S. I'm not sure why SceneFader is a monbehavior, rather than just a static class. Seems like not having to deal with the game object would make things simpler: MakeASingleInstance() for example could be a static function, called by any object that need it, in THEIR awake function. Matter of taste I guess.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fading To New Scene Problem? 1 Answer

Text field issue switching from scene to another scene 0 Answers

How to fade a gameobject containing child objects in it 0 Answers

Object not existing after reloading scene (nullreferenceexception) 1 Answer

iphone touch, only working in one scene 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges