Skip to content

Commit

Permalink
Reorder C# script properties to fix editor serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
hayahane committed Sep 16, 2024
1 parent 6681f25 commit 3ca81a3
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "csharp_script.h"

#include "core/error/error_macros.h"
#include "core/object/object.h"
#include "godotsharp_dirs.h"
#include "managed_callable.h"
#include "mono_gd/gd_mono_cache.h"
Expand Down Expand Up @@ -1497,11 +1499,23 @@ bool CSharpInstance::get(const StringName &p_name, Variant &r_ret) const {

void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const {
List<PropertyInfo> props;
script->get_script_property_list(&props);
ERR_FAIL_COND(!script.is_valid());
#ifdef TOOLS_ENABLED
for (const PropertyInfo &prop : script->exported_members_cache) {
props.push_back(prop);
}
#else
for (const KeyValue<StringName, PropertyInfo> &E : script->member_info) {
props.push_front(E.value);
}
#endif

// Call _get_property_list
for (PropertyInfo &prop : props) {
validate_property(prop);
p_properties->push_back(prop);
}

ERR_FAIL_COND(!script.is_valid());
// Call _get_property_list

StringName method = SNAME("_get_property_list");

Expand All @@ -1524,10 +1538,25 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const {
}
}

props.reverse();
for (PropertyInfo &prop : props) {
validate_property(prop);
p_properties->push_front(prop);
CSharpScript *top = script.ptr()->base_script.ptr();
while (top != nullptr) {
props.clear();
#ifdef TOOLS_ENABLED
for (const PropertyInfo &prop : top->exported_members_cache) {
props.push_back(prop);
}
#else
for (const KeyValue<StringName, PropertyInfo> &E : top->member_info) {
props.push_front(E.value);
}
#endif

for (PropertyInfo &prop : props) {
validate_property(prop);
p_properties->push_back(prop);
}

top = top->base_script.ptr();
}
}

Expand Down

0 comments on commit 3ca81a3

Please sign in to comment.