Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Resolved ScriptableObject vs Prefab Variant

Discussion in 'Prefabs' started by Goty-Metal, Dec 8, 2020.

  1. Goty-Metal

    Goty-Metal

    Joined:
    Apr 4, 2020
    Posts:
    168
    After reading tons of posts and blogs i'm still not sure what would be the best way to hadle my situation, i'm working on a tower defense, various towers, projectiles, enemies...
    I'm not sure if i should go for ScriptableObjects to store data for the different objects like:
    - Enemies: name, health, speed, abilities, animation, sounds, defense type (enum)...
    - Towers: range, sprite, projectile prefab...
    - Projectiles: speed, damage, sprite...

    Currently i'm using ScriptableObjects for enemy stats and prefab variants for the towers, that's why i'm currently stuck, not sure which one use i don't want to mix everything without sense.

    Thanks in advance!
     
    Last edited: Dec 8, 2020
    Bumpty likes this.
  2. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    65
    I'd use scriptable objects for data that I'd like to share between multiple objects and prefab variants when I want to have a new prefab that is mostly the same as the base but with a few variations (hence the name). Kinda like subclassing.
    There is nothing stopping you from mixing and matching both ideas however. You don't necessarily need to choose one or the other. They are both there to be used.
     
    Goty-Metal likes this.
  3. vestigial

    vestigial

    Joined:
    May 9, 2015
    Posts:
    193
    I'd use both:

    Projectile is the basic prefab with a ProjectileMovement component, which has a ProjectileSpeed scriptable object field. By default it points to an instance of ProjectileSpeed on disk with reasonable values.

    FastProjectile is a prefab variant whose ProjectileMovement component's ProjectileSpeed scriptableobject field points to a different instance on disk, one with higher values.

    SlowProjectile is a prefab variant whose ProjectileMovement component's ProjectileSpeed scriptableobject field points to a third, different instance on disk, one with lower values.

    etc. Prefabs to define which behaviours an object has, scriptableobjects to define the parameters of the behaviour, prefab variants to tweak which set of parameter values populate the behaviour, thats how I think of it anyway
     
    Goty-Metal likes this.
  4. Goty-Metal

    Goty-Metal

    Joined:
    Apr 4, 2020
    Posts:
    168
    Thanks guys, you're right i'm starting to mix both and it looks logical and works goods :)
     
unityunity