I have a script with a List :
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class Test : MonoBehaviour
{
public List<Conversation> conversations = new List<Conversation>();
And when using only Editor script I could do :
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
[CustomEditor(typeof(Test))]
public class TestTriggerEditor : Editor
{
private SerializedProperty _conversations;
private void OnEnable()
{
_conversations = serializedObject.FindProperty("conversations");
}
But now I want to do it in a EditorWindow script :
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public class TestingEditorWindow : EditorWindow
{
private SerializedProperty _conversations;
[MenuItem("Testing/Editor")]
private static void ConversationsSystem()
{
const int width = 340;
const int height = 420;
var x = (Screen.currentResolution.width - width) / 2;
var y = (Screen.currentResolution.height - height) / 2;
GetWindow<TestingEditorWindow>().position = new Rect(x, y, width, height);
}
private void OnGUI()
{
_conversations = serializedObject.FindProperty("conversations");
}
}
But I’m getting error on the line inside the OnGUI :
_conversations = serializedObject.FindProperty("conversations");
The error is on the serializedObject :
The name ‘serializedObject’ does not exist in the current context
If I’m changing it to SerializedObject I’m getting error :
An object reference is required for the non-static field, method, or property ‘SerializedObject.FindProperty(string)’
I tried to change the _conversations to be static but it didn’t help.