Unity3D ‘does not denote a valid type’
I am assuming you are receiving something like the error below:
Assets/Scripts/exampleJSScript.js(3,17): BCE0018: The name ‘exampleCScript’ does not denote a valid type (‘not found’).
This is because (per folder) Unity3D compiles C# scripts after JavaScript. So when a JavaScript file comes up for compilation, and it makes reference to a C# script the compiler hasn’t reached yet, an error occurs.
The solution is to place the C# script you can’t access from JavaScript into either the Standard Assets, Pro Standard Assets or Plugins folder, as these folders will have their contents dealt with before your usual scripts folder.
Example:
Assume we have a scene, and two scripts. The JavaScript is attached to an object in the scene, and the C# script doesn’t need an object in this case. Both scripts are in the same folder: a user scripts folder I created.
The JavaScript ‘exampleJSScript‘:
This script simply makes reference to the C# script, and grabs a public static int which it prints to the console.
1 2 3 4 5 6 |
#pragma strict var exCscript : exampleCScript; function Start (){} function Update (){ Debug.Log(exCscript.i); } |
The C# script ‘exampleCScript‘:
This script simply holds a public static int.
1 2 3 4 5 6 7 8 |
using UnityEngine; using System.Collections; public class exampleCScript : MonoBehaviour { public static int i = 0; void Start (){} void Update (){} } |
I get an error from this setup:
Assets/Scripts/exampleJSScript.js(3,17): BCE0018: The name ‘exampleCScript’ does not denote a valid type (‘not found’)
Now, if I take the C# file ‘exampleCScript‘ and drag it into the Standard Assets folder, the error vanishes, and I can play the scene: the console correctly shows ’0′ being printed.
Pingback: Unity3D: does not denote a valid type error | VISUALS+CODE