- Home /
'new' keyword compilation issue on transferring game to new PC
I am totally confused, as I had to relocate my game to another faster laptop. Both laptops run with Windows8.1 and Unity 5.2.0f3 personal.
On the 2nd laptop suddenly the error comes up: You are trying to create a Mono Behavior using the 'new' keyword in several of my C# files. Here follows part of the code of one of my files where this error occurs. Basically I am just creating an array of Vector3. The previous laptop didn't have this problem at all. To be sure I moved my game to a third laptop, with the same problem. Can anybody help me out ? Thanks a lot:
public class Fifo : MonoBehaviour {
private int N; //used fifo length
private static float T;
public Vector3[] value = new Vector3[200];//max available fifo length
public float[] time = new float[200];//max available fifo length
private bool full = false;
private int fillLevel = 0;
//constructor
public Fifo(int fifoLength)
{
this.N = fifoLength;
}//end constructor()
public void shift(Vector3 newvalue, float newtime)
{
int i = 0;
while (i < this.N - 1) {
this.value [i].x = this.value [i + 1].x;
this.value [i].y = this.value [i + 1].y;
this.value [i].z = this.value [i + 1].z;
this.time [i] = this.time [i + 1];
i = i + 1;
}//end while
this.value [this.N - 1].x = newvalue.x;
this.value [this.N - 1].y = newvalue.y;
this.value [this.N - 1].z = newvalue.z;
this.time [this.N - 1] = newtime;
if (!this.full)
this.fillLevel = this.fillLevel + 1;
if (this.fillLevel >= this.N)
this.full = true;
}//end shift()
That's generally a warning (yellow !) not an error; you might have turned off warnings in your Unity console options on the other computer.
Answer by Suddoha · Oct 11, 2015 at 12:30 PM
You are not supposed to create a class derived from MonoBehaviour by your own constructor which you've defined there and which is probably called somewhere in another script, as Unity does the actual object creation internally when a component is added to a gameobject.
For initialization, Awake and Start should be used.
So far there doesn't seem to be any code in that class that needs access to a MonoBehaviours members, so you could remove the inheritance (perhaps you simply forgot to remove it).
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Cant get Monodevolop to work 0 Answers
Glitch in Monodevelop for loops!!! 1 Answer
MonoDevelop won't open in Unity 5? 5 Answers