Jump to content
  • Advertisement
standinonstilts

Unity Proper use of scriptable objects in unity 2d

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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); 
}

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!