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?
Proper use of scriptable objects in unity 2d
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);
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement