Search Unity

Generic prefab with scriptable objects vs just a prefab

Discussion in 'Scripting' started by Justa5, Apr 19, 2019.

  1. Justa5

    Justa5

    Joined:
    Jan 23, 2019
    Posts:
    15
    Hi guys,

    in my 2d game I have several enemy types. They all have the same size and only differ in stats and the sprite (as the size is the same, also the collider is always the same).
    My current approach is to have a scriptable object for each enemy type, containing the stats and the sprite of the enemy and using a generic enemy prefab to bring that configuration "to life". The heavy lifting here is done in an enemy script attached to that prefab, which needs an enemy configuration and uses this to initialise the sprite of the sprite renderer, etc.

    As I guess that this is a relatively common pattern (the first thing that comes to my mind would be a tower defence game, in which the towers are also only different in regards to the stats and the visuals) I wanted to know if this approach is actually somewhat of a good practice, or if using a specific prefab for each enemy type would be the better approach (because for example the SO approach I have implemented has already some bigger issues I just don‘t see yet).

    What is your opinion about it? Which approach would you go for? What are the benefits? Or is there maybe even a completely different option?

    Thanks for your help!
     
    Last edited: Apr 19, 2019
  2. TomPo

    TomPo

    Joined:
    Nov 30, 2013
    Posts:
    86
    Well...
    When was testing some RPG with items for me easiest way was by SO.
    Was easy just to create other items with different stats, names, prefabs, icons, etc in the editor creating new SO by created menu in the editor. For me, that was way easier to manage.
    Second - you don't have to create all new objects by a script at the beginning but create them form SO when needed.