"the script needs to derive from monobehaviour"

I deleted a model from the project and tried to add another one, with the same name. But now when I tried to add the behaviour script, i get the error - "Can’t add Script behaviour. The script needs to derive from monobehaviour! "

So what do i need to do get it working?

One reason can be like if your Script file name and the class name are different. Make sure both filename and class name are same.

Its because the script you’re trying to add isn’t deriving from MonoBeahviour :smiley:

I know, I’ll show an example:

public class example
{
    int x;
    string y;
}

The above class/script you would not be able to attach to an object in the editor but if it was changed to:

public class example : MonoBehaviour
{
    int x;
    string y;
}

This allows the script to be attached to an object in the editor. It also opens up a bunch of extra functionality you can use within your script.

Could also be caused by existing compile errors in other parts of the code… Also make sure the class is public.

edit: along with this answer

I fixed this problem in my project by removing a space from the name of the script.
I.e. changed “Speech Manager.cs” to “SpeechManager.cs”.

The way I fixed my problem was by creating the script in the first folder of my Project tab (which was Assets) and then from there I moved it to my script folder and everything worked fine. I just couldn’t create and use the script in a sub folder… weird.

I had the same issue, had MonoBehaviour , and my script was the right name. Then I just added it to the execution order… and it worked. no idea why.

I got this error when I was doing roll a ball, and I am now currently stuck, on my 5th start over of a project in a few weeks

File name is PlayerControllerII

using UnityEngine
using System.Collections;

public class PlayerControllerII : MonoBehavior {


public float speed;

private Rigidbody rb;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”)
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}

@Blaze-the-Fox-2 replace MonoBehavior with MonoBehaviour (note the “u” near the end)