Skip to content

Commit

Permalink
Fix getting properties state when reloading C#
Browse files Browse the repository at this point in the history
When reloading C# classes and keep their properties values they are
retrieved and stored in a state list.
Retrieving the properties was only getting the fields of the C# class
and not inherited fields so those properties values were lost on reload.
Now we also try to find the field in the parent classes.
  • Loading branch information
raulsntos committed Dec 28, 2021
1 parent a75afd6 commit 907e709
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,19 @@ void CSharpInstance::get_properties_state_for_reloading(List<Pair<StringName, Va

ManagedType managedType;

GDMonoField *field = script->script_class->get_field(state_pair.first);
if (!field)
GDMonoField *field = nullptr;
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
field = top->get_field(state_pair.first);
if (field) {
break;
}

top = top->get_parent_class();
}
if (!field) {
continue; // Properties ignored. We get the property baking fields instead.
}

managedType = field->get_type();

Expand Down

0 comments on commit 907e709

Please sign in to comment.