- Home /
BCE0019 errors in Custom Editor script
A quad is created from a menu item , then it can be edited in edit mode. However my Custom Editor cannot see the quad.
Assets/Editor/SQuadInspector.js(29,24): BCE0019: 'size' is not a member of 'UnityEngine.Object'. etc, etc ...
The editor script is the problem, the quad script is just a generic pocedural 4 vert mesh script.
My Editor script :
#pragma strict
// Add menu to the main menu
@MenuItem ("Custom Item/Create Empty as SQuad")
static function CreateGameObjectAsSQuad()
{
var go : GameObject = new GameObject("GameObject");
go.transform.name = "sQuad";
go.transform.position = Vector3.zero;
go.AddComponent("SQuad");
}
// ----
@CustomEditor (SQuad)
class SQuadInspector extends Editor
{
// Using a SerializedProperty after the object has been deleted is not possible.
// UnityEditor.DockArea:OnGUI()
private var btnWidth : GUILayoutOption = GUILayout.MaxWidth(80.0);
private var btnCenter = new GUIContent("Center", "Recenter quad");
///* // ----
function OnInspectorGUI()
{
EditorGUILayout.BeginHorizontal();
target.size = EditorGUILayout.Vector2Field("Size", target.size);
target.center = EditorGUILayout.Vector2Field("Handle", target.center);
EditorGUILayout.EndHorizontal();
if(GUILayout.Button(btnCenter, btnWidth))
{
target.center = Vector2.one/2.0;
target.Construct();
}
EditorGUILayout.BeginHorizontal();
target.uvSize = EditorGUILayout.Vector2Field("uvSize", target.uvSize);
target.uvOffset = EditorGUILayout.Vector2Field("uvOffset", target.uvOffset);
EditorGUILayout.EndHorizontal();
if (GUI.changed)
{
target.Construct();
}
}
//*/ // ----
///* // ----
function OnSceneGUI()
{
if (GUI.changed)
{
EditorUtility.SetDirty (target);
}
}
//*/ // ----
}
My SQuad script :
remember this is just for reference to my editor script.
#pragma strict
@script RequireComponent(MeshFilter, MeshRenderer)
// ----
// instead of @script ExecuteInEditMode()
@ContextMenu ("Do Something")
function DoSomething ()
{
Debug.Log ("Perform operation");
ConstructOnCreation();
}
function ConstructOnCreation()
{
if(!mesh){
GetComponent(MeshFilter).mesh = mesh = new Mesh();
verts = new Vector3[4];
uv = new Vector2[4];
tris = new int[6];
normals = new Vector3[4];
mesh.name = "sQuad Mesh";
}
Construct();
}
// ----
public class SQuad extends MonoBehaviour
{
public var size : Vector2 = Vector2.one;
public var center : Vector2 = Vector2.one / 2.0;
private var mesh : Mesh;
private var uv : Vector2[];
private var verts : Vector3[];
private var tris : int[];
private var normals : Vector3[];
private var origVerts : Vector3[];
public var uvSize : Vector2 = Vector2.one;
public var uvOffset : Vector2 = Vector2.zero;
function Start()
{
if(!mesh){
GetComponent(MeshFilter).mesh = mesh = new Mesh();
verts = new Vector3[4];
uv = new Vector2[4];
tris = new int[6];
normals = new Vector3[4];
mesh.name = "sQuad Mesh";
Construct();
}
}
function Update ()
{
if (Input.GetMouseButtonUp(0)) Construct();
}
function Construct()
{
verts[0] = new Vector3( size.x * (0 - center.x), size.y * center.y, 0);
verts[1] = new Vector3( size.x * (0 - center.x), -size.y * (1-center.y), 0);
verts[2] = new Vector3( size.x * (1 - center.x), size.y * center.y, 0);
verts[3] = new Vector3( size.x * (1 - center.x), -size.y * (1-center.y), 0);
uv[0] = new Vector2(uvOffset.x, 1.0 - uvOffset.y);
uv[1] = new Vector2(uvOffset.x, 1.0 - uvOffset.y - uvSize.y);
uv[2] = new Vector2(uvOffset.x + uvSize.x, 1.0 - uvOffset.y);
uv[3] = new Vector2(uvOffset.x + uvSize.x, 1.0 - uvOffset.y - uvSize.y);
normals[0] = -Vector3.forward;
normals[1] = -Vector3.forward;
normals[2] = -Vector3.forward;
normals[3] = -Vector3.forward;
tris[0] = 0;
tris[1] = 2;
tris[2] = 1;
tris[3] = 1;
tris[4] = 2;
tris[5] = 3;
mesh.vertices = verts;
mesh.uv = uv;
mesh.triangles = tris;
mesh.normals = normals;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}
Debug.Log("target " + target.GetType() ); gives target SQuad UnityEngine.Debug Log(Object) SQuadInspector OnInspectorGUI()
the error is Assets/Editor/SQuadInspector.js(32,24): BCE0019: 'size' is not a member of 'UnityEngine.Object'.
Size is a public variable in SQuad
public class SQuad extends $$anonymous$$onoBehaviour
{
public var size : Vector2 = Vector2.one;
I think I may have solved it with var targetObject = target as SQuad;
script has changed again, but not updated here (am tired of UDN changes affecting script posting).
Answer by DaveA · Aug 04, 2012 at 12:11 AM
I assume that 'target' means Editor.target which is of type Object. You would need to cast it to whatever type has .size and .Construct and all that.
How could I cast, or more specifically, set it to the object that is selected in the Hierarchy window of my project? So the Inspector view is for every object of type sQuad, but manipulates the individual variables in the SQuad script attached to the highlighted gameObject?
as in my comments while testing, this was correct. I started with var targetObject = target as SQuad;
then changed all my target
vars to targetObject
. I have other problems with the inspector working correctly and throwing more errors, but that is another question.
Your answer
Follow this Question
Related Questions
Can you have custom EditorGUILayout fields? 0 Answers
Type casting SerializedProperty.objectReferenceValue doesn't work? 3 Answers
How to get fields of a custom script through SerializedProperty.FindPropertyRelative? 1 Answer
Using a CustomEditor in the inspector and also seeing normal inspector fields 1 Answer