Search Unity

Implementing unique behavior for Items (Scriptable Objects)

Discussion in 'Scripting' started by ZPendragon, Mar 20, 2019.

  1. ZPendragon

    ZPendragon

    Joined:
    May 24, 2018
    Posts:
    2
    Hi all, I'm new here, working on my own solo ARPG project. I have what I believe to be a fairly simple question but I'm drawing a blank when I try to find a solution.

    In my project I am working on a Consumable System for my Playable Characters, (Health Potion, mana potion, rage potion, etc). So far I've created an abstract base class for all Items and the base class for the Consumable items. For example, I have a Consumable class that derives from an Item: ScriptableObject class.

    My newbie question is, regarding the specific implementation details between each unique Potion, where should that implementation live? Should I subclass from Consumable every time I create a new potion? Should this information/behavior live in another asset that I attach to each ?

    Thank you in advance!
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Well, that's depends. If you have attributes/effects system in your game, then you probably don't need to subclass because potions just modify attributes and/or add effects for consumers. But if you don't then I suggest you implement different logic in separate scripts, like a components: consumable, item, healer or cunsumable item poison. This way anything may be poisonous - a sword, a spikes, a snake, a potion.
     
  3. ZPendragon

    ZPendragon

    Joined:
    May 24, 2018
    Posts:
    2
    Thanks for your quick reply @palex-nx. I do have many effects I intend to implement (Poison, stun, etc). If I understand correctly, you are suggesting I create separate Components to handle these behaviors and just pass my ScriptableObject with the data to use, ie how poisoned is the entity from the given interaction. Thanks again!
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Yes. And if you have effects system, you don't need your consumable to contain exclusive effect description. You may create common consumable. I mean, in the consumable description you just choose some action it executes upon consumption, so all consumables actually are things of same class.