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 deltamish · Aug 16, 2013 at 08:10 AM · editorarrayclasscustomeditor

Custom Editor Script Problem!!

Hi everyone I was working on Advanced AI Script.For which i had to make a Editor Script I wanted to add Array(Using List for that) of classes to the Editor Script.

So After Trying a lot i finally diceded to browse for it in Google Finall i found a soultion in (C#) but when i tried to impliment it

It seems to give Object reference not set to instace of object

Here is the script cut short

 import System.Collections.Generic;
 @CustomEditor(typeof(simpleAI))
 @UnityEngine.SerializePrivateVariables
 @CanEditMultipleObjects
 class AIEditor extends Editor{
   
 // Use this for initialization
 @SerializeField
  var AIScript:simpleAI;
 @SerializeField
 var AI_Script:SerializedObject;
 @SerializeField
 private var ShowIdlTransform:List.<boolean>;
 private var Show:boolean;

 function OnEnable(){
     
     AI_Script = new SerializedObject (target);  
     AutoMap = AI_Script.FindProperty("AutoMapWaypoints");
     
     }
   
      function OnInspectorGUI(){
      
     AIScript = target as simpleAI;
     TransformName = AIScript.gameObject.transform.name;
     super.OnInspectorGUI();
     
     serializedObject.Update();
     
     EditorGUILayout.Separator ();
     AI_Script.Update();
     
     var i:int=0;
     for(var Idl:IdleTransform in AIScript.IdleTrans){
     //for(var i:int =0;i<ShowIdlTransform.Count;i++){
     
     EditorGUILayout.Foldout(ShowIdlTransform[i],"Transform Parent Set #"+i); //<<<<<<<<<_---------------- PROBLEM HERE              
     if(ShowIdlTransform[i]){
     ShowIdlTransform[i] = 
     Idl.TheTransform = EditorGUILayout.ObjectField("The Object",Idl.TheTransform,typeof(Transform)) as Transform;
     
     Idl.ItsParent =  EditorGUILayout.ObjectField("Its Parent",Idl.ItsParent,typeof(Transform)) as Transform;
     Idl.Transisition_Anim = EditorGUILayout.ObjectField("The Transition Aniamtion",Idl.Transisition_Anim,AnimationClip);
     
     }
     i++;
     //}
     
     }
     EditorGUILayout.EndVertical();
     if(GUILayout.Button("?")){
     Show =!Show;
     }
   
     if(GUILayout.Button("Add WeaponParent Transistioner")){
     AIScript.IdleTrans.Add(new IdleTransform());
     ShowIdlTransform.Add(true);
     }
     }
     
     AI_Script.ApplyModifiedProperties();
     }
     }

Here IdleTransform is a class

 simple AI
 
 var IdleTrans:List.<IdleTransform>;
 @System.Serializable
 class IdleTransform{
 var Transisition_Anim:AnimationClip;
 var TheTransform:Transform;
 var ItsParent:Transform;
 }

-------------------------------## Solution ##-----------------

Edit

Hi all i figured out the solution the problem was unity was resetiing the list of ShowIdlTransform[i]

The solution was to Add this line

 function Enable(){
         ShowIdlTransform=new List.<boolean>(new boolean[AIScript.IdleTrans.Count]);
         }

and

Alter this

     for(var i:int =0;i < AIScript.IdleTrans.Count;i++){
      ShowIdlTransform[i] =  EditorGUILayout.Foldout(ShowIdlTransform[i],"Transform Parent Set #"+i); 
 if( ShowIdlTransform[i]){
 Idl.TheTransform = EditorGUILayout.ObjectField("The Object",Idl.TheTransform,typeof(Transform)) as Transform;
     
     Idl.ItsParent =  EditorGUILayout.ObjectField("Its Parent",Idl.ItsParent,typeof(Transform)) as Transform;
 }
     }
Comment
Add comment · Show 8
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 Jamora · Aug 16, 2013 at 08:23 AM 1
Share

You need to let us know where the error is happening. The line number is mentioned in the error message. So posting that would give potential helpers here a chance.

Any . (period) is a potential null reference or object reference not set just waiting to happen. Your code has lots of periods.

avatar image deltamish · Aug 16, 2013 at 09:05 AM 0
Share

Hi Sorry a about that but i think i mentioned the line where the problem appears any way here it is

 EditorGUILayout.Foldout(ShowIdlTransform[i],"Transform Parent Set #"+i); 
 if(ShowIdlTransform[i]){...


NullReferenceException: Object reference not set to an instance of an object

AIEditor.OnInspectorGUI () (at Assets/Editor/AIEditor.js:109)
avatar image Sajidfarooq · Aug 16, 2013 at 09:37 AM 1
Share

It looks like you are trying to create a Foldout from ShowId1Transform when it doesnt exist. $$anonymous$$ove this line:

 EditorGUILayout.Foldout(ShowIdlTransform[i],"Transform Parent Set #"+i); 

to inside the "if" block right after it to make sure it only accesses it when it exists.

avatar image yogee · Aug 16, 2013 at 10:12 AM 1
Share

where is line 109

avatar image AlucardJay · Aug 28, 2013 at 08:16 AM 2
Share

looking at all the sh1t questions on the same page as this, this doesn't deserve a downvote compared to them, upvoted.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Adamcbrz · Aug 19, 2013 at 04:21 AM

It looks like you aren't ever connecting your serialized field private var ShowIdlTransform:List. to a property in your class. You need to use the FindProperty to connect it up otherwise it will give you an error.

Comment
Add comment · Show 1 · 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 deltamish · Aug 28, 2013 at 07:39 AM 0
Share

Hi sorry for the late reply(my internet was dead) i shall try it But i dont think thats the issue because var ShowIdlTransform:List`var ShowIdlTransform:List.` is only added to know the lenth of the list and for folddout to be true

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

20 People are following this question.

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

Related Questions

Setting a new runtime class variables gives Null reference 1 Answer

Pushing GameObject into JS Array returns NullReferenceException 1 Answer

Cannot edit values of Class when created using .JSON file 1 Answer

Problem with arrays in a list 1 Answer

How to initialize array[][] via SerializedProperty? 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