For some reason, searching for an ObjectField
by its name returns null
.
Here’s the code:
editEntityNameTextField = root.Q<TextField>("edit-entity-name-textfield");
editEntityNameTextField.value = string.Empty;
if (editEntityNameTextField == null) {
Debug.LogError("NameText is null");
}
editEntityPrefabObjectField = root.Q<ObjectField>("edit-entity-prefab-objectfield");
// editEntityPrefabObjectField.objectType = typeof(GameObject);
if (editEntityPrefabObjectField == null) {
Debug.LogError("ObjectField is null");
}
editEntitySaveButton = root.Q<Button>("edit-entity-save-button");
if (editEntitySaveButton == null) {
Debug.LogError("Button is null");
}
It returns a TextField
and a Button
without any problems. So, why there are problems with ObjectField
?
Here is the hierarchy of UI elements, you can see that the names match:
Console output: