2
\$\begingroup\$

I'm working on the prototype of my game, I want one of the options to have a very large amount of weapons. I have searched for tutorials, but I have only found weapons changes where the weapons have already been loaded in the scene from the inspector, like this https://youtu.be/Dn_BUIVdAPg where they are only activated and deactivated. But I want a game like dofus where there are hundreds of weapons, I think I have a data file of the weapons and so, I can load the correct model of the weapon. How can I get the model loaded?

I have read other tutorials regarding the AssetBundle, but I think that is when you need to download the models from a server for example, but I just want to load them from the same project.

sorry for the bad english

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

If you don't want to attach 100 weapon child-objects to your PlayerCharacter game object, then you could have a "Weapon Manager" behaviour in the scene which holds an array of prefabs with every weapon in the game. When a character switches weapons, Destroy the weapon it is currently holding and Instantiate the new weapon from the list of prefabs in the WeaponManager.

In this case, all weapons are loaded when the scene loads. That means weapon switching will be instantaneous. But the cost for that is a longer scene loading time and more memory consumption. You need to check how much time and memory this is for your particular game and if it's notable. When you are creating a sprite-based game like Dofus, then there is a good chance that this is actually negligible, but you might still be surprised (for example, one thing which is often underestimated are audio clips).

If you want to load the weapon prefabs the moment they are equipped, then you can put those prefabs into the directory [your Project]/Assets/Resources and load them at runtime with Resources.Load(). But keep in mind that when your weapons are detailed models with high resolution textures and high-quality sound samples, then switching weapons that way might cause a slight hickup. You are also responsible for unloading those weapons when they are no longer needed, or you are going to leak memory.

\$\endgroup\$
1
  • \$\begingroup\$ On top of that its worth noting that many games have a 2D icon for equipments, and every time you move to the "Next Page" of equipment, the new ones load, one at a time. This makes your game not consume as much memory (especially for a large number of weapons), and scales amazingly well. \$\endgroup\$ Feb 11, 2019 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .