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 /
avatar image
0
Question by hanann24 · Sep 03, 2017 at 06:21 PM · gameobjectsdestroygameobjectrestart game

DontDestroyOnLoad gameobject once destroyed is not reloading. How to reset scene to allow it reload?

My game has a gameobject that has a DontDestroyOnLoad method. I also have a pause menu that can access the main menu which is in a difference scene. My problem is that if I access the main menu from the pause menu then the gameobject carries over into the main menu scene. Yet if I destroy the gameobject, when clicking the new game button which loads the main scene then the gameobject is still destroyed. How would I go about resetting my main scene when I access it from the main menu so then the gameobject is created again? Thank you.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by FlaSh-G · Sep 06, 2017 at 10:58 AM

Why would you destroy the first GameObject anyway? If I understand you correctly, you simply don't want two of these GameObjects to exist. Why would you destroy the first one and try to use the new one if you could just destroy the new one and keep the old one?

 private static NameOfThisClass singleton;
 
 void Awake()
 {
   if(!singleton)
   {
     singleton = this;
     DontDestroyOnLoad(this);
   }
   else
   {
     Destroy(gameObject);
   }
 }

(This pattern only is viable if you really plan to only ever have one of this kind of script at a time.)

Comment
Add comment · Show 2 · 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 hanann24 · Sep 06, 2017 at 03:53 PM 0
Share

What I don't want is for the gameobject to be seen/shown on the main menu screen. $$anonymous$$y game starts on the main menu, you press the new game button and it takes you to first scene of the game where the gameobject which is the player is. From here if you press escape, a pause menu shows which has the option to go back to the main menu. On returning to the main menu the player/gameobject follows as it has don't destroy on load method. What I don't want is for the gameobject to come here and when I press new game I want the player/gameobject to reload e.g all of it stats back to what it would be on a new game

avatar image FlaSh-G · Sep 07, 2017 at 10:24 AM 0
Share

To me, this sounds a lot like you don't want to DontDestroyOnLoad the player. Whatever player related data you want to have between scenes, you can carry it along without DontDestroyOnLoad. With a/some static variable(s), for example.

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

68 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

Related Questions

Why are my Game Objects being destroyed? 0 Answers

How do I get a material from a GameObject? 1 Answer

Character animation problem 1 Answer

objects in the same array wont move 0 Answers

Transport objects between scenes. 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