Search Unity

Prefab design question

Discussion in 'Prefabs' started by Skullhac, Dec 26, 2018.

  1. Skullhac

    Skullhac

    Joined:
    Dec 5, 2016
    Posts:
    14
    Hi !

    I hope my question was not already asked, could not find any answer. Here is my problem :

    I have a game with a few enemies, each one with his own stats (hp, attack,...), his own sprite and hitbox. They share a script to modify these stats. I was planning to store these datas in an external JSON file, load it in my GameController and create enemies via a Factory which populate the characteristics of the enemy.

    But, I ran into an issue : sprites and hitboxes. I was using Prefabs to store these, and I added a "prefab" line in my JSON, but what's the point of using this JSON instead of directly storing the datas in the Prefabs ?

    In general, should I create one Prefab per enemy or one generic Prefab that will be modified by the stats I give to it ? If I do use one generic Prefab, how do I handle the different sprite and hitboxes ?

    What are you method for handling this type of situation ? In my case, one prefab per enemy won't be that hard, since I won't make more than 20 enemies I think, but I like to know and try to use "common" methods.

    Thx for reading !
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    I'd suggest using ScriptableObjects instead of JSON,. That way you can store references to Unity objects (sprites etc) in them and create your enemy from one or more generic prefabs using different ScriptableObjects as prototypes/templates.
     
    Skullhac likes this.