- Home /
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
Do you have another component called VectorGrid (in Plugins etc) perhaps not written by you but a plugin? Sounds like it's getting confused.
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?
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?
GetChild() is an undocumented, probably unsupported feature. I think they removed it because children are unordered. Can you rewrite alignTo() without using GetChild()?
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
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.
Doesn't look like he's using anything that requires it to be a $$anonymous$$onoBehaviour to me...
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.
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 ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613102423im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating 2d shapes with code and filling them 1 Answer