By LOOKM


2019-02-10 05:02:06 8 Comments

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

1 comments

@Philipp 2019-02-10 13:14:24

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.

@TomTsagk 2019-02-11 10:16:36

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.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] WebGL Freeze for some minutes after loading asset bundle

1 Answered Questions

[SOLVED] Stretching limited graphic assets in a loot based game

  • 2018-12-11 01:38:34
  • DasBeasto
  • 59 View
  • 3 Score
  • 1 Answer
  • Tags:   assets balance

1 Answered Questions

[SOLVED] Unity - Array of custom class with a superclass using generics does not show in the inspector

  • 2017-07-06 11:10:49
  • Enrique Moreno Tent
  • 312 View
  • 1 Score
  • 1 Answer
  • Tags:   unity

1 Answered Questions

[SOLVED] How to export from Blender to unity3d

1 Answered Questions

[SOLVED] How should I set up 2D animations for weapons in Unity?

Sponsored Content