Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ragefordragons · Nov 21, 2018 at 03:27 AM · classscriptableobjectinheritance

How to prevent an inherited variable from showing up on a scriptable object?

Okay so I created a scriptable object thats an item, and I then created another srcriptable object class for specifically equipment, which inherited the item class. This (of course) brought over all of the 'item' class'es variables, which for now include how much health that item will restore to the player as a float. ("healthHeal") However, since the equipment class inherits the item class, this means when you create a new equipment peice you can see you still have the option to change how much health it heals. I was wondering if there is a way to prevent specific variables from showing up in this instance, specifically so 'healthHeal' isnt shown when you are making a new equipment. And thoughts?

Here is the item class:

public class Item : ScriptableObject {

 new public string name = "New Item";
 [TextArea]
 public string description = "";
 public Sprite icon = null;
 public bool isDefaultItem = false;
 public float healthHeal = 0f;

 public ItemUse useText;

 public virtual void Use() //item is used, something might happen.
 {
     DamageTextController.CreateDamageText(healthHeal.ToString(), PlayerController.globalPLayerPosition, "Green");
     StatController.playerHealth = StatController.playerHealth + healthHeal;
 }

}

Here is the equipment class:

public class Equipment : Item {

 public EquipmentSlot equipSlot;
 public int armorModifier;
 public int damageModifier;

 public override void Use()
 {

     //Equip the Item
     EquipmentManager.instance.Equip(this);
 }

}

public enum EquipmentSlot { Helmet, Chestplate, Boots, Weapon, Charm}

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
1
Best Answer

Answer by JVene · Nov 21, 2018 at 03:56 AM

I submit that it is an error to think in terms of hiding variables with the purpose you have in mind. The problem is not that the base class has a "health" parameter that a derived object does not need, it is that the base class itself is polluted with the "health" parameter that should not be there.


This is a typical issue in object design. First, you've developed an object that works for a player (that has a need for health). Next, you create a derivative of that object as if it were a base, but it isn't a base, it's a player (that needs health). What you've demonstrated is a missing class that isn't there. You should now create a player class, derived from that base class, and MOVE health into THAT class (and anything else that isn't required by your equipment derivative). In this way you "clean" the base of the pollution that otherwise corrupts its position in your hierarchy as a base (a generic class that does all the things ALL of the derivatives must do - and in this context the term generic means general, not related to the 'generics' in C#).


Once you practice this (and you likely will end up in the same situation in the future), you'll realize it isn't that the language is missing a technique you'd like to use, but that by reorienting your thinking you'll realize the technique you require is associated with the concept that form is functional (that where you put code is part of the functional definition of that code). The feature you're thinking of using isn't required, just an adjustment of viewpoint.

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 ragefordragons · Nov 21, 2018 at 06:26 AM 0
Share

Thanks, I didn't think about that.

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

100 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

Related Questions

How to "include" an inherited C# Class into the file? 3 Answers

How to build up the class structure for an object 1 Answer

Multi inheritance in Boo 2 Answers

How can I redefine attributes of a parent in the child class? 1 Answer

Private variable is not saved 3 Answers


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