Proper use of scriptable objects in unity 2d

Started by
3 comments, last by Shaarigan 6 years, 3 months ago

I am creating a 2d rogue like as my first game in unity. I decided to create a scriptable object class called mob that contains all attributes that are associated with the npcs. I then use the asset menu to create several instances of this object such as: wizard, goblin etc. I also do this with the player asset. I want to create items that effect the stats of npcs and players, but i noticed that changes made to the scriptable object during runtime are permanent and remain after exiting the game. Is there a way to work around this / or is using scriptable objects even the right approach in this situation?

Advertisement

Using ScriptableObject for dynamic entities is the wrong way! We ever have at least two classes that are a special database for our entities (whatever it is, maybe an NPC or a merchant) which is setup on a ScriptableObject and a standard MonoBehavior class for this entity (like Merchant, Goblin, whatever) that is instantiated from the database object to pass all the values to it.

Adding Buffs/Debuffs is adding a function to a list of state effects on that entity. This functions are called with the basic value for lets say health or armor on evaluation, so a x1.5 multiplier will depending on its position in that list do


UInt16 Evaluate(UInt16 health)
{
   return Mathf.Round((float)health * 1.5f); 
}

 

So I should have one scriptable object to set the default values, and a monobehaviour class to instantiate those values and modify them in a game object?

Thats normally the way it works in Unity

This topic is closed to new replies.

Advertisement