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 Richard Slater · Oct 24, 2010 at 08:07 PM · loadingmemorydontdestroyonloadsingleton

How to keep assets in memory without duplication?

I am working on a project which contains four scenes the user moves from the first scene to one of the three others and back again, this is probably explained best with a picture:

alt text

Scene 1 and 2 contain a large shared asset (Several Meshes, 44MB at the moment but totally unoptimized) Scene 3 and 4 do not contain any shared assets. When exported to the web player moving between Scene 1 and Scene 2 is rapid there is a slight perceptible pause but not enough to even be able to read the word "Loading" on my loading screen.

However when moving from Scene 4 to Scene 1 or Scene 3 to Scene 1 (Red Arrows) there is a long pause. My first thought was to put the asset in Scene 3 and 4 which works but feels dirty. I also create a script which I could attach to the asset using DontDestroyOnLoad(this) this removed the delay but caused the asset to be duplicated on each subsequent load.

I have seen several scripts which apply DontDestroyOnLoad then Destroy(GameObject) the asset manually. This also feels quite dirty.

Is there a better way of keeping a large asset in memory and prevent an object from being instantiated multiple times.

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
1

Answer by Herman-Tulleken · Oct 25, 2010 at 07:10 AM

Here is one way to solve the persistence / duplication problem:

  1. Make you shared object into a prefab (or multiple prefabs)

  2. Make an empty game object ObjectSpawn, and put it in each scene.

  3. Create a script that first check whether the object exists, and if not, instantiates it. Call 'DontDestroyOnLoad' on the object. Attach the script to ObjectSpawn, and remove the shared objects from the scene.

I don't know whether this is cleaner than any other method, but it's worth considering (we usually use for our "logic" objects, not meshes).

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 Richard Slater · Oct 25, 2010 at 12:51 PM 0
Share

Thanks, I shall give this a go.

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

No one has followed this question yet.

Related Questions

Prevent Resources class from loading assets when application starts 1 Answer

FindObjectOfType or FindWithTag 1 Answer

Memory Locking While Loading Issue 0 Answers

singleton, global vars and dontdestroyonload 2 Answers

Long load time for scene... Some optimization questions. 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