I’m writing on an editor methods for deleting items from a list.
The list looks as follows
[Serializedfield]
private List<TextItem> _textItems;
public class Item<T>
{
public string Id;
public List<T> Contents = new List<T>();
public Item(string id, List<T> cont)
{
Id = id;
Contents = cont;
}
}
[Serializable]
public class TextItem : Item<string>
{
public TextItem(string id, List<string> cont) : base(id, cont)
{
}
}
I saw this question/answer and implemented it like this within my CustomEditor class:
private void DeleteText(int index)
{
SerializedProperty textList = serializedObject.FindProperty("_textItems");
if (textList.GetArrayElementAtIndex(index).objectReferenceValue != null)
{
textList.DeleteArrayElementAtIndex(index);
}
textList.DeleteArrayElementAtIndex(index);
}
It is basically working but I always get an error thrown
type is not a supported pptr value
UnityEditor.SerializedProperty:get_objectReferenceValue()
pointing to the line where I check for null.
I also saw this question/answer and intempted to do the type casting like
if(textList.GetArrayElementAt(index).objectReferenceValue as System.Object as TextItem != null)
but without effect.
How can I get rid of this exception?