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 janlovsin · Aug 25, 2019 at 03:15 PM · unity 5

Reaprenting in OnDestroy

When my game starts it loads objects in advance and binds it to a DoNotDestroyOnLoad object. It all works fine but the only problem I'm getting and I have no idea how to fix it is: if a scene needed those objects and I exit that scene, it calls reparent function to save objects from being destroyed...

      public void ChangeScene()
     {
         // This one will work as expected, but here you can see items
         // getting deleted in front of you, which looks kind of bad
         leaderboard.Reparent();
         SceneSwitcher.LoadScene2(GameSettings.INTRO_SCREEN);
     }
 
    private void OnDestroy()
     {
         // This one still normally calls the reparent function and debugging
         // it, it reparents it back to old object, but next time I'm getting to
         // needed screen it claims it destroyed all of them
         leaderboard.Reparent();
     }

For god's sake I can't fix it. And I need OnDestroy because it call's it later and looks way smoother than calling it just before changing scene.

Comment
Add comment · Show 7
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 sacredgeometry · Aug 25, 2019 at 03:52 PM 0
Share

Can you ins$$anonymous$$d of posting your solution which may be inherently flawed, ins$$anonymous$$d post what you are trying to achieve.

avatar image janlovsin sacredgeometry · Aug 25, 2019 at 04:00 PM 0
Share

Well I made a leaderboard, which renders 1000 players, for which it creates needed objects in the first scene and binds them to a DoNotDestroy object. Then each time I want to show the leaderboard, I activate those objects and SetParent to the scrollboard. When I quit the scene, I SetParent those objects back to the old one, but I do this right before calling Scene switch. So you see first deletion of all those objects and then the Scene changes and it looks ugly. So I wanted to move the function to OnDestroy, so that it happens in the background, but it just breaks.

avatar image Glurth janlovsin · Aug 25, 2019 at 04:54 PM 0
Share

Not quite clear which objects have DoNotDestory set, is it the leaderboard itself? if not why not? Regardless ... does this hide it?

 leaderboard.gameObject.SetActive(false);
 leaderboard.Reparent();
 SceneSwitcher.LoadScene2(GameSettings.INTRO_SCREEN);
 leaderboard.gameObject.SetActive(true); //assumes leaderboard has DoNotDestory flag set
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by janlovsin · Aug 25, 2019 at 10:38 PM

I have the following function which is called in OnDestroy in the needed scenes.

 public void Reparent()
     {
         for (int i = 0; i < contentAreaObjects.Count; i++)
         {
             contentAreaObjects[i].transform.SetParent(gameObject.transform, false);
         }
     }

The OnDestroy is called on the root object that contains the contentAreaObjects, but even after this method is called, the OnDestroy of contentAreaObjects is still getting called. Like what?

Calling the above function manually before OnDestroy works fine. Are the objects already queued to get destroyed when the function is called?

Comment
Add comment · 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

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

204 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Question regarding Delegates & Events 1 Answer

Once Trackable Library is found, How do I set a permanent Timer on the Augumented Objects ? 0 Answers

Unity 5.4.0f3 (64-bit) Crahed on startup! 2 Answers

Use standard shader on particles meshes 0 Answers

Does the animations done using slice modifier used in 3Ds max show the same animations in Unity ? 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