- Home /
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;
}
}
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.
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]){...
AIEditor.OnInspectorGUI () (at Assets/Editor/AIEditor.js:109)NullReferenceException: Object reference not set to an instance of an object
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.
looking at all the sh1t questions on the same page as this, this doesn't deserve a downvote compared to them, upvoted.
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.
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

Follow this Question
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