• 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 Jun 11, 2020 at 08:37 AM by Steventus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Steventus · Jun 11, 2020 at 07:27 AM · 2d-platformernullreferenceexception

Error after Build - NullReferenceException: Object reference not set to an instance of an object

For simplified context, I'm making a prototype 2D platformer with a main menu screen, and 3 levels with transitions in between them. The errors are: (1) there are no transition events, (2) cannot move to next levels from Player win-condition-collision detection. The relevant scripts are:

  1. The UI Manager handles a screen transition animation event (fade to black, fade to white), and other UI elements such as a win screen.

  2. The Game Manager handles building next level from player collision detection, restarting levels and sending inputs to UI Manager to do the transition.

  3. The PlayerController handles inputs for movement, jump, and trigger collision with the win condition, which sends an input to the game manager.

These are what I believe are considering the chain reaction of errors (but I might be wrong) - however I do not fully understand what I am doing wrong, as it appears perfect in editor mode, but not in build.

These are the errors found in the player log. alt text

And the relevant errors(?) in the code: PlayerController:

 public void OnTriggerEnter2D(Collider2D collision)
     {
         if (isCollidingwithWinCondition) return;
         if (collision.CompareTag("VictoryCondition"))
         {                       
             isCollidingwithWinCondition = true;            
             GameManager.instance.LoadNextLevel();
             StartCoroutine(Reset());
         }
     }
 IEnumerator Reset()
     {
         yield return new WaitForSeconds(1);
         isCollidingwithWinCondition = false;
     }

GameManager:

 public void LoadNextLevel()
     {
         //Get Active Scene
         thisscene = SceneManager.GetActiveScene();
 
         if (thisscene.buildIndex == SceneManager.sceneCountInBuildSettings - 1)
         {
             //Finish Game if win all Level
             WinGame();
             return;
         }
         else
         {
             //Waiting for Transition            
             UIManager.instance.StartTransition();
             StartCoroutine(Wait());
         }
     }
  IEnumerator Wait()
     {
         float TransitionTime = UIManager.instance.TransitionTime;
         yield return new WaitForSeconds(TransitionTime);
 
         //Load NextLevel
         thisscene = SceneManager.GetActiveScene();
         SceneManager.LoadScene(thisscene.buildIndex + 1);
     }

UIManager:

     void Start()
     {
         #region Singleton
         if (instance == null)
             instance = this;
 
         else if (instance != this)
             Destroy(gameObject);
 
         DontDestroyOnLoad(gameObject);
         #endregion
 
         Scene0 = SceneManager.GetSceneByBuildIndex(0).buildIndex;
         TransitionController = GetComponent<Animator>();
     }
 public void StartTransition()
         {
             TransitionController.SetTrigger("Start");
         }


Comment
Add comment · Show 4
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 ShadyProductions · Jun 11, 2020 at 07:56 AM 0
Share

What does TransitionController.SetTrigger("Start"); do? Also, did u select all required scenes in the build settings?

Show more comments

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

142 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 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 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

Allocating Game Object name dynamically using Find 0 Answers

Why am I getting a NullReferenceException while trying to set a gameobjects animation frame? 0 Answers

NullReferenceException .. problem with Camera.main.transform 2 Answers

Raycasting null object reference error 1 Answer

Editing in Animator removes Player tag 0 Answers


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