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

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

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.