• 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 Mexallon · May 17, 2013 at 07:32 AM · c#vectrosity

Must derive from MonoBehaviour or ScriptableObject

Hello everyone. I got this compiler warning which is driving me nuts because it just wont leave.

 The class defined in the script file named 'VectorGrid' is not derived from MonoBehaviour or ScriptableObject!

This kind of confuses my because I got more classes that are not derived from any of these.

Edit: This was not the root of my "can not build for IOS" problem. Though it confuses me. I could not build the iOS app cause I didnt read the Vectrosity Documentation (using source code now instead of dll and it works)

Here is the class that causes the error:

 public class VectorGrid{
 
     private float strength;
     private float height;
     private float lineOffset;
     private int lineCount;
 
     public VectorLine line;
     public VectorLine smallLines;
     
     public VectorGrid () {
         strength = 0.5f;
         height = 0.5f;
         lineOffset = 10f;
         lineCount = 10;
         
         float xOffset = -((lineCount-1) * lineOffset);
         float zOffset = -((lineCount-1) * lineOffset);
         Vector3[] arr = new Vector3[lineCount*4];
         
         // z axis
         for(int i = 0; i < lineCount*2 ; i+=2){
             arr[i] = new Vector3(i*lineOffset+xOffset, height, zOffset);
             arr[i+1] = new Vector3(i*lineOffset+xOffset, height, (lineCount-1)*lineOffset*2+zOffset);
         }
         // x axis
         for(int i = 0; i < lineCount*2 ; i+=2){
             arr[i+20] = new Vector3(xOffset, height, i*lineOffset+zOffset);
             arr[i+20+1] = new Vector3((lineCount-1)*lineOffset*2+xOffset, height, i*lineOffset+zOffset);
         }
         line = new VectorLine("Line", arr, Color.gray, null, strength);
 
     }
     
     public void alignTo(GameObject go){
         GameObject line = GameObject.Find("Vector Line") as GameObject;
         if(line == null)
             throw new Exception("VectorGrid: Line not found on scene");
         line.transform.parent = go.transform.GetChild(0);
         line.transform.position = go.transform.TransformPoint(Vector3.zero);
         line.transform.rotation = go.transform.GetChild(0).rotation;
         line.transform.Rotate(Vector3.right, 90f);
     }
 }

I appreciate any answer, comment or thought

Comment
Add comment · Show 8
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 whydoidoit · May 17, 2013 at 07:55 AM 0
Share

Do you have another component called VectorGrid (in Plugins etc) perhaps not written by you but a plugin? Sounds like it's getting confused.

avatar image Mexallon · May 17, 2013 at 12:40 PM 0
Share

Nope just that single class.

avatar image TonyLi · May 17, 2013 at 01:15 PM 0
Share

Where do instance(s) of this class exist? (For example, as a variable inside a $$anonymous$$onoBehaviour class.) Was this class ever a $$anonymous$$onoBehaviour that was attached to a game object?

Is any class trying to run Send$$anonymous$$essage or Broadcast$$anonymous$$essage on it?

avatar image Mexallon · May 19, 2013 at 12:03 AM 0
Share

Just one instance of this class exist in an $$anonymous$$onoBehaviour that is on the same object as another monobehaviour that sends messages to all scripts on that object. Is that a problem?

avatar image TonyLi · May 19, 2013 at 02:57 PM 1
Share

GetChild() is an undocumented, probably unsupported feature. I think they removed it because children are unordered. Can you rewrite alignTo() without using GetChild()?

Show more comments

3 Replies

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

Answer by Mexallon · May 26, 2013 at 11:52 AM

Ok. I removed the Transform.GetChild(int) method in my AlignTo method and the Warning seems to be gone.

Thanks TonyLi

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
avatar image
0

Answer by SubatomicHero · May 17, 2013 at 01:34 PM

At the end of your class definition you need to add :

public class VectorGrid : MonoBehavior { ///.... }

or if you don't want to derive from that, you need to remove anything you've declared that uses the MonoBehaviour class.

Comment
Add comment · Show 3 · 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 whydoidoit · May 17, 2013 at 03:15 PM 0
Share

Doesn't look like he's using anything that requires it to be a $$anonymous$$onoBehaviour to me...

avatar image SubatomicHero · May 17, 2013 at 03:30 PM 0
Share

What is Vectorline?

avatar image Mexallon · May 19, 2013 at 12:01 AM 0
Share

VectorLine is a class from the Vectorsity pack to draw Lines. And yes iam not using anything from monobehaviour (if you think of Update or something like that) but even though I could have a function called Update but it won't be called every frame.

avatar image
0

Answer by sunshineblocks · Dec 17, 2016 at 08:34 AM

I was saved by the following advice: "Remove the line "using UnityEditor" and all will be well ;)"

http://answers.unity3d.com/questions/1216116/the-class-named-is-not-derived-from-monobehaviour.html

Perhaps you can be too ;)

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 abeldantas · Feb 22, 2017 at 01:37 PM 0
Share

Either that or the script being in an "Editor" folder

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

18 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Is there a way to find a Vectrocity VectorLine object at runtime from a script? 2 Answers

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

Making a bubble level (not a game but work tool) 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