- Home /
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:
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!
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/
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.
Your answer
Follow this Question
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