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 coastwise · Dec 07, 2010 at 09:40 AM · inspectorinheritance

Does the Unity Inspector support Inheritance?

Not to be confused with this related question, I know Unity does Inheritance but I'd like to leverage it in the Inspector.

I'd like to be able to switch the action to be performed on-the-fly using buttons in the GUI. So, I've got a class AbstractAction that inherits from MonoBehaviour which has a single abstract method DoAction. I've written a couple of scripts that inherit from AbstractAction and override the method, and I want to assign them to specific slots in the GUI using the inspector (similarly to how I assign the Texture2Ds for the buttons themselves).

public class MyGui : MonoBehaviour {

 public Texture2D[] buttons;
 public AbstractAction[] actions;

 private int selectedAction;

 void OnGUI() {
     selectedAction = GUILayout.SelectionGrid(0, buttons, 2);
 }

 public void DoSelectedAction() {
     actions[selectedAction].DoAction();
 }

}

My problem is, the array is showing up fine in the Inspector (with elements "None (Abstract Action)"), but I cannot assign my subclasses of AbstractAction to them. Is there a way around this? I've tried using both an actual abstract parent, and a normal class with a virtual method.

Thanks in advance

Comment
Add comment · Show 1
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 Proclyon · Dec 07, 2010 at 09:45 AM 0
Share

I recall you need to make it serializable to make it show up there. But I'm not sure actually so posting it as comment/idea ins$$anonymous$$d of answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by coastwise · Dec 09, 2010 at 11:10 PM

Turns out this is possible to do. My problem was that I was attempting to drop the script itself into the array in the Inspector. Instead, it was expecting a GameObject (or prefab) that has an AbstractAction script (or a script that inherits from it) attached.

Ultimately I created a prefab for each action that contains both the texture and the action script subclass, and therefore only need a single array to define them both in the GUI. Clean, functional and properly captures the relationship between the image and the action!

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Values lost? 1 Answer

I have objects that have the same set of variables, but different desired behaviors. How can I do this without repeating variable declarations across all behaviors? 1 Answer

Check if gameobject has script with inheritance 2 Answers

c# enum wont show in inspector 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