You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a new object with the + button all the fields in the new object are set to the c# default for that type instead of their default values from the class constructor (ints + floats = 0, string = empty, bool = false).
I've tested by adding a field next to the list that is a singular object. This object is initialised correctly, but the objects in the list are not. How can I get this working correctly?
The text was updated successfully, but these errors were encountered:
Yes, this is a limitation of the Unity Editor. Values in lists are set to their defaults (AFAIK)
What you can do is listen to the onAdd event, and manually add an item to the list:
[CustomEditor(typeof(AudioManager))]
public class AudioManagerEditor : Editor {
private ReorderableList list;
void OnEnable() {
list = new ReorderableList(serializedObject.FindProperty("sounds"));
list.onAddCallback += OnListAdd;
}
private void OnListAdd(ReorderableList list) {
SerializedProperty property = list.AddItem();
property.FindPropertyRelative("name").stringValue = "new sound";
property.FindPropertyRelative("volume").floatValue = 1;
property.FindPropertyRelative("pitch").floatValue = 1;
}
public override void OnInspectorGUI() {
serializedObject.Update();
list.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
When creating a new object with the + button all the fields in the new object are set to the c# default for that type instead of their default values from the class constructor (ints + floats = 0, string = empty, bool = false).
I've tested by adding a field next to the list that is a singular object. This object is initialised correctly, but the objects in the list are not. How can I get this working correctly?
The text was updated successfully, but these errors were encountered: