Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by Elit3d · Jan 14, 2015 at 09:40 PM · c#errorobjectscenedontdestroyonload

DontDestroyOnLoad with object on another scene

So I have an Options UI on my main menu and a pause UI on my level1. I want to make it so when I press the back button, it will go to my pause menu. That currently doesnt work. right now I am using "GameObject.Find("pause").SetActive(true);" and it isnt working I get an error saying: "NullReferenceException: Object reference not set to an instance of an object optionsprompt.BackButton (UnityEngine.Object myObject) (at Assets/optionsprompt.cs:67)" line 67 is the code I showed. Why is this happening and is there a better way of doing this?

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 tanoshimi · Jan 14, 2015 at 09:44 PM 1
Share

Sounds like there isn't a gameobject in your scene called "pause"...

avatar image Elit3d · Jan 14, 2015 at 10:09 PM 0
Share

@tanoshimi its a prefab, does this affect it?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by skylem · Jan 14, 2015 at 10:22 PM

My best advice would be to create a GameManager Gameobject that will hold all your data for your player and his activitys and then u would use this gameobject to activate your pause menu for you. for example.

 public GameObject pauseMenu; // drag your pause menu object into here
 public bool paused; // This is your off switch
 
 if(Input.GetKeyDown(Keycode.Escape) && paused == false) {
      pauseMenu.SetActive(true);
      paused = true;
 }
 else if(Input.GetKeyDown(Keycode.Escape) && paused == true) {
      pauseMenu.SetActive(false);
      paused = false;
 }

hope this helps

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 Elit3d · Jan 14, 2015 at 10:25 PM 0
Share

I already figured it out but yes this was somewhat the issue that I didnt think to try out hahaha thanks for the response I shall accept this as the answer

avatar image
1

Answer by Mondkin · Jan 14, 2015 at 10:13 PM

GameObject.find() doesn't find inactive objects. That is why it is returning null, so you better work with the enabled/disabled state of its elements (not the GameObject itself).

From the documentation:

If no game object with name can be found, null is returned. If name contains a '/' character it will traverse the hierarchy like a path name. This function only returns active gameobjects.

And by the way, you are not alone, this is a common catch and several people have wanted that feature to be added:

  • GameObject.Find () find inactive objects too

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 Elit3d · Jan 14, 2015 at 10:18 PM 1
Share

I figured out my issue by doing this: GameObject.Find("PauseFunctions").GetComponent().Pause$$anonymous$$enu.SetActive(true); I never thought to try that. $$anonymous$$any thanks for the help though I shall give +rep

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Scene restarting problem 0 Answers

Some Copies of Prefab Detect Clicks But Others Don't 1 Answer

Changing something in another scene by answering correctly with GlobalManager 0 Answers

NullReferenceException - When destroying Object 1 Answer

Unknown reason for NullReferenceException error 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