1
\$\begingroup\$

I have been looking around for information regarding this process but I was unable to come across anything that would help me out. Basically, in a game where you may have many items or enemies or player objects, how would one go about creating these objects?

Am I supposed to be creating every single one of these objects as a prefab and then load them into the game when needed? Or is it possible to create one object that has references to the different variables needed to create the above objects and then load in from an external source all the necessary information? And then during run time, depending on what object I am looking at, the script will 'create' the object with the information from the external source.

Meaning, if I decide to have 50 different enemies in my game, do I need to make 50 prefabs, one for each enemy? Or just one prefab that loads in data pertaining to the 50 different enemies and then build upon that information?

Thank you!

\$\endgroup\$
  • 2
    \$\begingroup\$ It really depends on your own preference and skill. You are able to do whatever you want. \$\endgroup\$ – Gnemlock Nov 16 '16 at 22:53
  • \$\begingroup\$ Yes, I understand I am able to do whatever I want. My question is just what is the more efficient approach? What makes more sense to do and is it even possible to create one object that conforms to MANY objects based on data provided \$\endgroup\$ – D34thSt4lker Nov 17 '16 at 4:03
1
\$\begingroup\$

If all the enemies are the same (model, material, script etc) then create one prefab and reuse it. If you have 50 different enemy types with unique components you will need 50 prefabs. It all depends on your needs.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Mhm, I know that if they were the same exact I would just reuse the same prefab X amount of times. I'm thinking more in terms of several different types of enemies . (ie: ogre, zombie, troll) but where all of them would derive from one base class and have similar components. In this case, would I be able to use one prefab but then attach different images and other necessary components based on which enemy it is or would it make sense to just make a new prefab for each one? \$\endgroup\$ – D34thSt4lker Nov 17 '16 at 14:39
1
\$\begingroup\$

I would say if you know Entity Component System, and instead of inheritance would use aggregation, then you can go with one prefab. I will try to explain what I mean. You can have one prefab with components, like behaviour, movement, visual(graphic) and so on. Then you can build some sort of factory, which will produce you a different type of enemy, by instantiating an enemy prefab, loading correct asset(3d model, texture, material, etc.) and passing it to visual component; add appropriate behaviour and movement scripts and so on. It will give you a lot of flexibility. But the solution with multiple prefab configured correctly will work well. It's more about preferences.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.