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
7
Question by chris Etches · Nov 17, 2009 at 10:35 AM · iphoneoptimization

Preloading / Caching Prefabs [Unity iPhone]

The first time I Instantiate prefabs in my game (particularly ones that use large bitmap textures) there is a noticeable lag / delay before they appear, subsequent times after this they then appear instantly. Is the best way of dealing with this to Instantiate then Destroy all the problematic assets before first gameplay?

ChrisError

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

4 Replies

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

Answer by duck · Nov 17, 2009 at 11:33 AM

A useful technique for iPhone is to instantiate things that you'll need for your gameplay during your menu screens, so that by the time the user clicks 'play', everything has already been preloaded.

Also, wherever possible, re-use a pool of instantiated objects rather than destroying and then re-creating objects each time new ones are required.

Also you should spread out your instantiation over a number of frames, so that there isn't a large hiccup caused by a number of items being instantiated all during the same update.

You might find you need to write some kind of instantiaton manager, which handles instantiating a queue of items over a number of frames.

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

Answer by equalsequals · Nov 26, 2009 at 09:43 PM

To add to Duck's comment,

With iPhone the garbage collection is a bit tricky. Even if you destroy the only instance of an object, garbage collection can neglect to clean it up. In a previous project we found that several "destroyed" Game Objects were still in memory after dumping old scenes and loading new ones.

We found the only way to truly destroy dynamically instantiated objects was to do the following:

Destroy(myObj);
myObj = new GameObject();

This will let GC know that you are using that variable for something else now and that it is safe to be collected.

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 SisterKy · Jan 08, 2010 at 04:37 PM 1
Share

As loginstubbornmoose's question went unnoticed, I'd like to ask the same... because your example would instantiate a new GameObject which should be avoided if possible, no?

avatar image
0

Answer by stubbornmoose · Nov 27, 2009 at 03:31 PM

Will it help to GC if we do this?

Destroy(myObj);

myObj = null;

Thanks

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

Answer by equalsequals · Jan 08, 2010 at 08:12 PM

To answer SisterKy:

Yes, you do want to avoid this in most cases. This is just the solution I found for a very specific case.

To explain, when developing for iPhone my team found that memory remained allocated after GC passes even though the object had been destroyed. As an important note I should mention that the GameObject in question was dynamically instantiated from Resources.Load(), not manually instantiated via the Editor.

We tried setting all references to the object to null, but this made no difference to the memory as per Instruments' readout. What we discovered was that if we immediately instantiated a blank object in place of the destroyed object, GC did pick it up and memory was freed.

Does that clear it up at all?

==

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

No one has followed this question yet.

Related Questions

How to implement an ammo counter using textured quads? [Scripting doubts] 2 Answers

Swiping images across the screen - iPhone 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What is the expected behaviour of Dynamic Batching? 2 Answers

Whats the best way to setup a screen like this... 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