Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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
0
Question by cat_dawg · May 19, 2021 at 06:09 PM · pausereloadpause menumenu screenrestart game

After "Restarting/Reloading" a level, I have multiple pause screens.

Hello all! New to Unity here.

I have successfully implemented a restart button on my game's UI, however when I utilize my pause screen, it seems I have to click through multiple canvasses before I can finally un-pause. The number of clicks/canvasses correlate to the # of times I reloaded the screen. Any advice or help is appreciated! Thank you!


public void RestartLevel() { SceneManager.LoadScene("level1"); }


I have a game manager script utilizing the DontDestroyOnLoad(gameObject); Could that be the problem?

Comment
Add comment · Show 1
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 Casiell · May 19, 2021 at 08:44 PM 0
Share

Yeah, that's probably part of the problem, but we would really need to see the part of code responsible for showing the pause screen

1 Reply

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

Answer by EDevJogos · May 19, 2021 at 11:53 PM

@cat_dawg I think what you said is problably the reason for you to having multiple instances of the same object, since when you load a scene it will instatiate all the objects belonging to it and bring over all objects that are tagged dont destroy on load from the current scene.

The most likely solution to your problem is to check if a instance of that object already exists and if so destroy it.

You can do that with the following lines of code:

 private static YourClassName Instance;
 
     private void Awake()
     {
         if (Instance != null)
         {
             Destroy(gameObject);
         }
         else
         {
             Instance = this;
         }
     }
Comment
Add comment · Show 3 · 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 cat_dawg · May 20, 2021 at 08:43 PM 0
Share

I had a feeling, I just didn't know the right words! I will try this and hopefully it fixes my issue. Should I be putting this in my "Pause" script? Could I also utilize this line of code but still keep the DontDestroy script on my Game Manager?

Thank you so much!!

avatar image EDevJogos cat_dawg · May 22, 2021 at 05:12 PM 0
Share

Use these code on every object that has dontdestroy, it will prevent the game from creating duplicates of the same object.

avatar image cat_dawg EDevJogos · May 24, 2021 at 05:34 AM 0
Share

Thank you very much! It worked perfectly!

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

120 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

Related Questions

Pause Game 1 Answer

Countdown after resume game. 4 Answers

Pause Game Through Button UI Click Instead of Escape Key? 2 Answers

How to make a pause menu with Gui Texture?? 2 Answers

Game stays paused after Restart. 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