瀏覽代碼

Fixes OptionButton selection index being reset to zero at instanciation

Bug: engine tries to set selected item before items were added during save scene/run project, because of wrong properties order.
Fixes #10213.
Alexander Alekseev 7 年之前
父節點
當前提交
66c39b1426
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      scene/gui/option_button.cpp

+ 2 - 1
scene/gui/option_button.cpp

@@ -318,8 +318,9 @@ void OptionButton::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("_set_items"), &OptionButton::_set_items);
 	ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
 
-	ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
 	ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
+	// "selected" property must come after "items", otherwise GH-10213 occurs
+	ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
 	ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "ID")));
 }