You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehavio

Hi
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all

the line to rewrite is:
mySurface = new BSplineSurface();

how to rewrite? Many thanks

as the error says, use AddComponent:

mySurface = gameObject.AddComponent <BSplineSurface> ();
1 Like

Many thanks, what about this line. I get an error about int
// int[ ] triangles = new int[(height - 1) * (width - 1) * 6];
int[ ] triangles = gameObject.AddComponent(int[(height - 1) * (width - 1) * 6]);

Hi Mike4,
int[(height - 1) * (width - 1) * 6] is not a component, so you cannot use it.
Perhaps you would like to have a look here, it will short things out:

If I try it the other way round I get:
The class named ‘BSplineSurface’ is not derived from MonoBehaviour or ScriptableObject!

Thanks