• 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 codejoy · Aug 14, 2014 at 09:29 PM · javascriptinheritanceclassesunity 4.2

can't place inherited class of an abstract class in editor?

I saw this:

http://answers.unity3d.com/questions/24635/can-abstract-classes-inherit-abstract-methods-with.html

So I basically built two classes one my abstract class as such:

 public abstract class TriggeredScript : MonoBehaviour
  {    
 public abstract void RunTrigger();
 public abstract void StopTrigger();
  }

Then I created a more specific script:

 public class GasScript : TriggeredScript
 {

     // Use this for initialization
     public Rect area;
     
     void Start ()
     {
 
     } 
             ...
 }


Then I have a game object with a script on it:

 public class Switch : MonoBehaviour 
 {
 public DoorTrigger[] doorTriggers;
 public TriggeredScript[] eventTriggers;
 public bool sticky; 
     ...
 }


in the editor it has TriggeredScript which my GasScript extends, why can it not add it in the editor to the field?
(yes its an array and i have the size as one showing one slot but cannot drag the script over)

is this kind of encapsulation just not handled by unity especially in the editor ?? or fingers crossed am I just doing something dumb and missing to add or do something else.

edit FIGURED IT OUT! I will answer my own question for posterity, but it seems I had to drop the GasScript on a Gameobject, and set the array that has triggered script to the gameobject with the script. Why this seemed different this time I don't know, in fact it is always like that?! Oh well, fixed!

if i can find the delete I might do that cause this was just me being dumb.

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 IvovdMarel · Aug 14, 2014 at 09:39 PM 0
Share

You should be able to drag a GameObject with the Component GasScript onto the array, not the script itself. Otherwise I'm not sure what's going wrong.

avatar image codejoy · Aug 15, 2014 at 04:35 AM 0
Share

let me set up a screen shot...

so nope tried again no can do, no idea what I am missing... alt text

nocando.jpg (309.1 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by rutter · Aug 15, 2014 at 04:39 AM

Judging by comments, you're trying to drag the script file itself into the inspector field.

So, your variable:

 public TriggeredScript[] eventTriggers;

It's an array of references to objects of type TriggeredScript.

And the value you're trying to drop in? That's a class. Classes aren't objects.

The class TriggeredScript defines all the things that objects of that type can do... but the class itself is only a template for an object. It's sort of like the difference between a blueprint and a house.

If you have a GasScript that exists in your scene, that's an object, which you should be able to drop into the inspector field.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity exports my derived class, but not its base class (C# OOP) - Is there a workaround? 0 Answers

Classes VS Variable Scripts 1 Answer

Why use inheritance? 3 Answers

Create a new script object from a class which inherits from MonoBehavior 4 Answers

Can I preserve the values in a parent class when I overwrite it with a child class? 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