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
0
Question by Bentley · Jan 19, 2015 at 12:22 AM · prefaboptimization

Do bulk prefabs cause performance issues?

I'm making a 2D game and I want to be able to spawn in a large variety of different weapons (like 1,000+). Are prefabs the best way to go about doing that or should I put all the information for each weapon into an XML document and load that at runtime to dynamically create each weapon? I'm fairly new to Unity so I don't know if that's the norm but having that many prefabs seems heinous, although it would be much easier.

Thanks!

Bentley

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 DaDonik · Jan 19, 2015 at 12:36 AM 0
Share

Do you have different textures/sprites for each weapon? If so, how large are they? Is it a PC or mobile game?

This would be vital information for a good answer.

avatar image Bentley · Jan 19, 2015 at 12:48 AM 0
Share

Each weapon has a different sprite sheet which contains multiple sprites for attachments, like a scope and a suppressor. The largest I have so far is 20.0 kb according to the Unity inspector. It is going to be a PC game, but I would like to keep it as light as possible as I will probably move it to mobile as well after it is finished. Also each prefab will have approximately 10 components attached (various managers and network scripts).

2 Replies

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

Answer by DaDonik · Jan 19, 2015 at 07:43 AM

If one of your weapons is as small as 20kb, that still means you have around 20mb in memory, if you want to show all 1000+ at once. Since you maybe want to have that game on mobile devices, 20mb's is quite large. I guess the weapons are not everything in your game, so it will get even bigger than that.

Assuming that you will have some kind of a weapons shop, you could make weapon categories and only show one category at a time. That way not all weapons will be in memory at the same time, which can make a huge difference on mobile devices. It might lag a bit when loading the next category, but with that amount of weapons you don't have much choices.

For PC only i would load all the weapons at once when loading the scene you use to display them, or at game start. This will of course, like abi.kr01 says, add to the loading time, but at least it won't lag while playing.

Regarding your question on prefabs vs. XML: XML might be more flexible when you want to change something later on, but the extra time spend parsing 1000+ XML's files will make it slower. It won't be much slower, at least not on PC, but somewhat slower. That said, i would probably use a SQLite database for this purpose.

I can recommend this plugin for database stuff on PC and mobile: SimpleSQL

Comment
Add comment · Show 3 · 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 Bentley · Jan 19, 2015 at 08:49 AM 0
Share

If I were to do X$$anonymous$$L I would not have 1,000 files. I would have one file with a thousand tags and children tags like and . I would then hold just the file in memory and read from it as needed. I guess the main question I was trying to ask is whether or not prefabs require memory even if they are not instantiated, or if they only require memory after instantiation. I would not be displaying all of the weapons at once, only 50 or so max, which even then would be highly unlikely and infrequent. If they require memory prior to instantiation I would go with X$$anonymous$$L, as a single X$$anonymous$$L file will be much smaller than 1,000 prefabs, but if memory is only allocated after instantiation then I don't see any downside to the prefab option, as I'm not particularly worried about application size. Let me know if any of that logic isn't sound for some reason or another.

Thanks! Bentley

avatar image DaDonik · Jan 19, 2015 at 09:00 AM 0
Share

The prefabs would only increase your build size, until you instantiate them.

Your original question led me to the assumption you want to display all at once, dunno why...

To put it in a nutshell, do what you feel most comfortable with =)

avatar image Bentley · Jan 19, 2015 at 09:07 AM 0
Share

Alright, thanks!

avatar image
0

Answer by abi-kr01 · Jan 19, 2015 at 05:44 AM

There are two ways you can do this either create an xml and create prefab at run time when you need them or you may use object pulling, all the items will we available on scene, no need to create new game-object.level loading will be slow in if you use object pulling.

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

27 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

Related Questions

Prefab with UI.Text is not unloaded 1 Answer

Hundreds of weapons, best practice 0 Answers

About Model Combine Optimization? 1 Answer

Huge prefab file sizes 0 Answers

How are prefab parameters stored in instances? 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