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 ScottMcG · Nov 25, 2011 at 08:06 PM · resourcesresources.load

What is the cost of using Resources.Load?

I'm working on a driving game that requires up to 20 traffic car prefabs in the world at a time. They will spawn and unspawn regularly, so the total number in game will probably fluctuate between 5 and 20. My question is about the most efficient way to do this (I can't find information on it anywhere). Is there much cost of creating GameObjects during gameplay?

Option 1 - Create my prefab instances on startup, store them at an unused world location, then move them in and out as I need them.

Option 2 - Make the traffic cars a resource and create them during gameplay using Resources.Load() then instantiating GameObjects.

Comment
Add comment · Show 2
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 Eric5h5 · Nov 25, 2011 at 09:22 PM 0
Share

It's frequently better not to use Resources.Load, but ins$$anonymous$$d link prefabs using public variables in the inspector. This way Unity can manage your assets intelligently.

avatar image CHPedersen · Nov 25, 2011 at 09:29 PM 0
Share

I thought so too; I'm happy to see you agree. Linking them that way makes the editor initialize the variable at runtime, right? (Just checking to see I have this down right)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CHPedersen · Nov 25, 2011 at 09:12 PM

Resources.Load involves accessing the harddrive, which is notoriously slow because it contains moving parts. So you're better off loading all the resources you need at startup, and then either manipulate their visibility or instantiate prefabs without using Resources.Load to provide the model.

For your particular scenario, however, I'd recommend creating a public Transform variable in your script, and then drag the car prefab onto it in the editor. Calling Instantiate by passing in that prefab Transform causes objects to be spawned without constantly looking at the harddrive to acquire the model to clone.

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 sicklepickle · Aug 27, 2012 at 08:20 AM

Just posted this on a similar topic, but gonna repost similar info anyway.

In my case preloading multiple versions of every possible spawn (over 40 available types) was using almost all of the 3GS\Droid's memory. On the flipside not creating a pool meant tons of stuttering. The solution was to create just one temp copy of each object and use newObj = (GameObject)Instantiate( pool[index].gameObject );

In my case this solved the problem entirely - Instantiate() seems be much faster than Resources.Load().

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 konsnos · Jul 01, 2014 at 09:26 AM 1
Share

Instantiate and Resource.Load are a different thing. To compare them performance-wise makes no sense.

Check out the documentation.

http://docs.unity3d.com/ScriptReference/Resources.Load.html

http://docs.unity3d.com/ScriptReference/Object.Instantiate.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading resources into a ScriptableObject instead of Resources.Load? 1 Answer

ridiculous load time using Resources.Load() on android build 0 Answers

Referencing prefab in code without using editor or Resources.Load? 0 Answers

Why does resources.load not work or what am I doing wrong? 1 Answer

Resources not loading in APK 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