Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 CG-DJ · Apr 10, 2014 at 08:18 PM · c#variableinspectorclassinheritance

Parent Class variables in Child Class's Inspector (C#)

Ok, I've just started to experiment with inheritance, but I think this should work.

I'm building a player character with a combat system. Here is what I'm trying to do with my scripts:

alt text

The idea is to have a class hierarchy that lets me group information into packets that are easier to evolve, organize, and build from. Each script down the line adds the variables it needs to run and uses the variables from the class before.

The problem is, in the inspector, each class is showing all of the variables, both from the class above it and from its own class. I want to edit just one set of variables, not have a new set for each class I add to the player.

Right now, I have each of these classes in a different script, and all the scripts attached to the player. I have each class inheriting by the line:

 public class CharacterMotor : TopLevelPlayerClass

I'm sure you probably need more information, but I really don't know what to give. What I want is to have 1 set of variables, not a set for each script!

Thank you for the help!

hoi class structure.png (20.8 kB)
Comment
Add comment · Show 2
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 getyour411 · Apr 11, 2014 at 01:19 AM 0
Share

Consider posting this in UA forums where open-ended discussions about design patterns and practices are frequent; duplicate question re: inheritance; likely to cause opinions and long subjective replies with no definitive answer.

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/inheritance

http://berniesumption.com/software/inheritance-is-evil-and-must-be-destroyed/

avatar image ProtoTerminator · Sep 25, 2016 at 12:26 AM 0
Share

It's kind of tedious, but you can make a custom inspector for each sub class and only show the fields that you want to. I don't know of an automated way to do this.

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

How do I show a variable in my base class in the inspector? 3 Answers

HideInInspector with inherited variables 1 Answer

Values lost? 1 Answer

Inheritance best solution to handle *many* instances of a class with unique values? 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