UnityScript static variables is not a member of a script

[SOLVED] You probably want to change the name of your ModelImporter class. Unity already has a ModelImporter defined. I just have to change the name of the ModelImporter class. Thanks Brian : Unity Answers

The Script I am having problems with.

Unity complains that :
ImportWindowUI.js(21,33): BCE0019: ‘modelImported’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(22,26): BCE0019: ‘modelImported’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(22,57): BCE0019: ‘modelPending’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(22,87): BCE0019: ‘processingModel’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(25,42): BCE0019: ‘modelImported’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(26,58 ): BCE0019: ‘modelImported’ is not a member of ‘UnityEditor.ModelImporter’.
ImportWindowUI.js(27,65): BCE0019: ‘ReturnProcessedModel’ is not a member of ‘UnityEditor.ModelImporter’.

The errors come after I put #pragma strict. But I don’t think it is an issue of dynamic typing.

ImportUI script:

#pragma strict

private var modelimporter : ModelImporter = (GameObject.Find("Browser").GetComponent(ModelImporter) as ModelImporter);

private var menuExpanded : Boolean = false;
private var processedModels : GameObject[];
private var typeButton : int = 0;
public var typeTexture : Texture[];

public var skin : GUISkin;
public var background : Texture2D;
public var typeBackground : Texture2D;

function OnEnable () {
	Debug.Log("ImportWindowUI log : Enabled");
}

function OnGUI () {
	var tempSkin : GUISkin = GUI.skin;
	GUI.skin = skin;
	Debug.Log(ModelImporter.modelImported);
	if(ModelImporter.modelImported || ModelImporter.modelPending || ModelImporter.processingModel) {
		Debug.Log("ImportWindowUI log : ModelImporter alert");
		if(GUI.Button(Rect(15, 15, 40, 40),"buildingButton")) {
			if(ModelImporter.modelImported) menuExpanded = !menuExpanded;
			if(menuExpanded  ModelImporter.modelImported) {
				processedModels = modelimporter.ReturnProcessedModel();
			}
		}
		if(menuExpanded  processedModels.length > 0) {
			GUI.BeginGroup(Rect(15, 55, 150, processedModels.length * 50));
				var gameobjectArray : GameObject[] = processedModels;
				for(var i = 0; i < gameobjectArray.length; i++) {
					if(GUI.Button(Rect(0, i*50, 150, 50), gameobjectArray[i].name)) {
						typeButton = GUI.SelectionGrid(Rect(150, i*50, 200, 50), typeButton, typeTexture,3);
						if(GUI.Button(Rect(350, i*50, 50, 50), "tick")) {
							Debug.Log("ImportWindowUI log : typeButton = " + typeButton);
						}
					}
				}
			GUI.EndGroup();
		} else if (processedModels.length == 0) {
			menuExpanded = false;
		}
	}
}

and below is the ModelImporter Script:

#pragma strict

import System.IO;

static var modelPending : Boolean = false;
static var modelImported : Boolean = false;
static var processingModel : Boolean = false;

private var modelPaths : Array = new Array();
private var processedModel : Array = new Array();
private var model : GameObject;

function Update () {
	if(modelPaths.length > 0  !processingModel) {
		ImportModel(modelPaths.Shift());
	}
	if(processedModel.length > 0) {
		modelImported = true;
	} else {
		modelImported = false;
	}
	if(modelPaths.length > 0) {
		modelPending = true;
	} else {
		modelPending = false;
	}
}

private function ImportModel (path : String) {
	processingModel = true;

	if (Path.GetExtension(path) == ".obj") {
		// do stuff and return;
	} else if(Path.GetExtension(path) == ".dae") {
		//do stuff and return;
	} else {
		Debug.Log("ModelImporter log : Cannot process 3D model with extension = " + Path.GetExtension(path));
		// return;
	}
}

public function PostProcessModel (message : String) {
        processedModel.Push(model);	
        processingModel = false;
}

public function AddModelPaths (path : String) {
	modelPaths.Add(path);
}

public function ReturnProcessedModel () : GameObject[] {
	return (processedModel.ToBuiltin(GameObject) as GameObject[]);
}

Any suggestions would be much appreciated…

Because it’s not. :slight_smile: Technically a static field, property or method belongs to the class declaration… but it does not belong to any instance of the class. So in this case you would have to say:

ModelImporter.processingModel = true;

Same way when accessing it. Since it’s “static” you have to access it through the class itself and not through an instance of the class. If that variable needs to be unique for each instance, then remove the static keyword.

I tried to do that, it does not help. I understand that a static variable exists only once to the class. And the line you are suggesting is the ModelImporter script itself, so there is no need to declare the class in front of its own variable anyways. The complaint comes from the ImportUI script which is the first piece of code.

Thanks for your quick reply!

Look at your ModelImport class though… the very first line of “ImportModel” is going to throw an error because you’re setting:

processingModel = true;

That’s invalid. You have to say ModelImport.processingModel = true;

I would also make sure this line actually returns something:
private var modelimporter : ModelImporter = (GameObject.Find(“Browser”).GetComponent(ModelImp…

You need to post the actual error message so we can see the line number and what’s going on, that way we don’t have to read through and interpret your entire script because I think there are multiple issues here.

[EDIT above] in the original post

Do you mean doing something like this??

ModelImporter.js :

#pragma strict

import System.IO;

static var ModelImport.modelPending : Boolean = false;
static var ModelImport.modelImported : Boolean = false;
static var ModelImport.processingModel : Boolean = false;

No no…

Here, replace your ModelImporter with this:

#pragma strict

 

import System.IO;

 

public static var modelPending : Boolean = false;

public static var modelImported : Boolean = false;

public static var processingModel : Boolean = false;

 

private var modelPaths : Array = new Array();

private var processedModel : Array = new Array();

private var model : GameObject;

 

function Update () {

    if(modelPaths.length > 0  !ModelImporter.processingModel) {

        ImportModel(modelPaths.Shift());

    }

    if(processedModel.length > 0) {

        ModelImporter.modelImported = true;

    } else {

        ModelImporter.modelImported = false;

    }

    if(modelPaths.length > 0) {

        ModelImporter.modelPending = true;

    } else {

        ModelImporter.modelPending = false;

    }

}

 

private function ImportModel (path : String) {

    ModelImporter.processingModel = true;

 

    if (Path.GetExtension(path) == ".obj") {

        // do stuff and return;

    } else if(Path.GetExtension(path) == ".dae") {

        //do stuff and return;

    } else {

        Debug.Log("ModelImporter log : Cannot process 3D model with extension = " + Path.GetExtension(path));

        // return;

    }

}

 

public function PostProcessModel (message : String) {

        processedModel.Push(model); 

        ModelImporter.processingModel = false;

}

 

public function AddModelPaths (path : String) {

    modelPaths.Add(path);

}

 

public function ReturnProcessedModel () : GameObject[] {

    return (processedModel.ToBuiltin(GameObject) as GameObject[]);

}

I’m really not entirely sure why you’re needing static variables there…

Also just updated it… you need to make sure those static fields are “public”… that’s why you’re getting your errors.

Ya I did that, the same errors. And it doesn’t matter if I declare them public or even private (of course also with some public functions accessing the private variables), the compiler is still giving those errors.

Thanks,
Aaron

I dunno… I could rewrite it in C# and make it work. :stuck_out_tongue:

I think adding “public” in front of static doesn’t help either.

Thanks a lot anyways! :smile: