Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Konjointed · May 23 at 04:53 PM · scriptableobject

Using ScriptableObjects for player health?

So I'm not great with scriptable objects so I'm not sure if this is a good use of them, but I decided to use a scriptable object for player info/data

 public class PlayerInfo : ScriptableObject
 {
     public float maxHealth;
     public float health;
     public float shield;
 
     public BaseClass playerClass;
     public List<BaseAbility> abilities;
 
     public Controls controls;
 }

Currently, I use a health script that has the health values and methods such as SetMaxHealth() and Damage(), but doing the scriptable object approach I'm a bit confused now on how I'd use it. Would I still want to have a health script that controls the health? Or would wanna have a reference to this scriptable object and the health script just adjusts the values in it?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jackmw94 · May 24 at 08:45 AM

The answer is a big fat "depends". Scriptable objects are pretty much configuration files for the elements within your game that won't change. They're a great fit for holding what bullets come out of a gun or how fast it fires. Maybe in this example you can pick up a rate-of-fire pickup that changes this but the gun still has a base rate of fire which is constant and configured in its associated scriptable object.

So tell me about your player - is this a player that you can choose from a set of possible players who each have different attributes? Do you get to a character select screen and see an array of characters with different maxHealth, shield and abilities? If so then yeah, I'd say scriptable objects are a great fit for this.

However, if your player is a fixed entity with health and shield that changes as the game progresses then maybe scriptable objects aren't such a great fit. If you're thinking that scriptable objects would save your player's health between games then this should instead be handled by a proper saving/loading system since the scriptable objects will not save their changed data between plays once built.

Unless I am misunderstanding it, I don't think "controls" would be a good fit for inclusion here. I am assuming by this you're choosing between your input device, e.g. keyboard, mouse, ds4? This seems like something that the player would want to change in settings rather than have as a fixed attribute of the player so is less suited for the scriptable object. Also "health" seems like something that will be set at the start of the game and changed frequently, so similar verdict.

If I've made any assumptions that invalidate my points then let me know in the comments and we can discuss :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Konjointed · May 25 at 12:24 AM 0
Share

Ok so if I'm understanding this right scriptable objects are for things that you don't want to be changed? So using it to store info about a class like the amount of health it gives and abilities is good? So for example I can have a Warrior class with 100 health, 6 walk speed, 3 abilites, etc.

For the PlayerData SO though I think I got confused because my plan was to kind of have it hold all of these values and change them throughout mainly when they select a class I just update the variables to what the class ones are. And then other scripts can reference it like the movement or health code, but it sounds like it's just better to do it in a mono behavior?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to serialize and store custom structs on the iPhone in scriptableObjects? 2 Answers

Serializable types for ScriptableObject 2 Answers

Is there any way to implement 'Undo' for ScriptableObject assets? 1 Answer

increamenting speed periodically 0 Answers

How to work with custom class (ScriptableObject) SerializedProperty? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges