Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AlucardJay · Aug 03, 2012 at 11:52 PM · editorcustomeditoroninspectorgui

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();
  }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Aug 04, 2012 at 03:55 AM 0
Share

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;
avatar image AlucardJay · Aug 04, 2012 at 04:38 AM 0
Share

I think I may have solved it with var targetObject = target as SQuad;

avatar image AlucardJay · Aug 04, 2012 at 10:03 AM 0
Share

script has changed again, but not updated here (am tired of UDN changes affecting script posting).

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Aug 04, 2012 at 02:32 AM 0
Share

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?

avatar image AlucardJay · Aug 04, 2012 at 10:02 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to add UnityEvent using Custom Inspector? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges