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 23, 2018 at 09:10 PM by yonxers for the following reason:

Other

avatar image
1
Question by yonxers · Jul 18, 2018 at 01:30 AM · bug-perhapsnull reference exception

Why am I getting a Null Reference Exception when the reference is set? (in build only, works correctly in editor)

Hello,

I have tried to solve this and researched similar issues for 2 days now, and haven't been able to figure it out.

I have project with a Game scene, which additively loads Navigation and Home asynchronously. Up until this point things have been going smoothly, but I'm now trying to trigger some animations on UGUI elements in Navigation based on Home's OnEnable/OnDisable (Home gets changed out with different scenes through the navigation). It's at this point I discovered reference errors in my build, using a nifty in-build console plug-in.

I have been using code like this:

navigationAnimationManager = GameObject.Find("NavigationManager").GetComponent<NavigationAnimationManager>();

which has worked nicely in play mode, but when I run the build I get a null reference exception. The weird part is that is that I'm getting the NRE even though my debug log says that it found the component, i.e. not null or blank.

I've tested this a number of ways, and they all fail the exact same way:

  • I've tried manually setting the reference through a public variable in the editor, on the same object, just to see if it would work.

  • I've tried using a getcomponent on the same object.

  • I've tried setting a tag and loading the object through the tag.

  • I've tried using the same code in a new script, in a new scene, on a different object (still referencing NavigationAnimationManager)

  • I've tried using a singleton defined in Game

  • I've tried random things like changing OnEnable to Start, loading the scenes synchronously, or waiting for the scenes to finish loading with a coroutine.

    None of these have worked, when I'm pretty sure a lot of these are valid ways to do things. I get the Null Reference Exception every time. Anyone have an idea??? I'm running out.



alt text



     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.UI;
     using UnityEngine.SceneManagement;
     
     public class HomeManager : MonoBehaviour
     { 
         private NavigationAnimationManager navigationAnimationManager;
         [SerializeField] private ScrollRect scrollContentScrollRect;
     
         private void OnEnable()
         {
             navigationAnimationManager = GameObject.Find("NavigationManager").GetComponent<NavigationAnimationManager>();
     
             if (GameManager.homeController.firstTimeOnHome)
             {
                 scrollContentScrollRect.verticalNormalizedPosition = 30.0f;
             }
             else
             {
                 navigationAnimationManager.TriggerSettingsButtonOn();
                 scrollContentScrollRect.verticalNormalizedPosition = GameManager.homeController.scrollPosition;
             }
         }
     
         private void OnDisable()
         {
             navigationAnimationManager.TriggerSettingsButtonOff();
     
             //Store scroll position and set flag to trigger some animations
             GameManager.homeController.scrollPosition = scrollContentScrollRect.verticalNormalizedPosition;
             GameManager.homeController.firstTimeOnHome = false;
         }
     }
 
 

screenshot-20180716-153250.png (200.0 kB)
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0

Answer by KrytalityStudios · Jul 18, 2018 at 01:40 AM

@yonxers Try maybe restarting the editor (although I'm sure you've done that, just making sure)? Check and make sure that there is nothing deleting the NavigationAnimationManager GO at runtime. If it is not one of those two things, sounds like a bug.

EDIT: Now I see about the build part. There could be several things going wrong if it is an actual build. For one, if the NavigationAnimationManager is being instanced after you call the GetComponent or the object is supposed to be loaded from another scene and it isn't. Lots of things could be haywire but I would recommend those. Sounds kinda crazy whatever it is.

Comment
Add comment · Show 1 · 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
avatar image yonxers · Jul 18, 2018 at 02:02 AM 0
Share

Thanks for your response @$$anonymous$$rytalityStudios

As far as I can tell, NavigationAnimation$$anonymous$$anager is instantiated and then GetComponent is called successfully each time. Unless something weird is going on under the surface.

That component is on the root object of the Navigation scene as well, I'm pretty sure it's being loaded correctly since other things depend on it.

Gonna try some more extreme things...

Follow this Question

Answers Answers and Comments

87 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

Related Questions

New blank project with 3 leaked textures ??? 1 Answer

Problem with lights. Why is this happening? 0 Answers

Creating gameobjects using script and assigning sprites to some of them breakes batching (both static and dynamic). Bug? 1 Answer

Input.GetAxis("Mouse ScrollWheel") not working without wheel being clicked in 2 Answers

Issue where if I click a button then press W,A,S,D the value of my sliders go down by 10 or up by 10 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