diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index caf502de9d0..62a6b96bb53 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -745,10 +745,9 @@ void CSharpLanguage::reload_assemblies_if_needed(bool p_soft_reload) { for (Map, Map > > >::Element *E = to_reload.front(); E; E = E->next()) { Ref scr = E->key(); - scr->signals_invalidated = true; scr->exports_invalidated = true; + scr->signals_invalidated = true; scr->reload(p_soft_reload); - scr->update_signals(); scr->update_exports(); //restore state if saved @@ -1579,37 +1578,33 @@ bool CSharpScript::_update_exports() { return false; } -bool CSharpScript::_update_signals() { - if (!valid) - return false; +void CSharpScript::load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class) { - bool changed = false; - - if (signals_invalidated) { - signals_invalidated = false; - - GDMonoClass *top = script_class; - - _signals.clear(); - changed = true; // TODO Do a real check for change - - while (top && top != native) { - const Vector &delegates = top->get_all_delegates(); - for (int i = delegates.size() - 1; i >= 0; --i) { - Vector parameters; - - GDMonoClass *delegate = delegates[i]; - - if (_get_signal(top, delegate, parameters)) { - _signals[delegate->get_name()] = parameters; - } - } - - top = top->get_parent_class(); - } + // no need to load the script's signals more than once + if (!signals_invalidated) { + return; } - return changed; + // make sure this classes signals are empty when loading for the first time + _signals.clear(); + + GDMonoClass *top = p_class; + while (top && top != p_native_class) { + const Vector &delegates = top->get_all_delegates(); + for (int i = delegates.size() - 1; i >= 0; --i) { + Vector parameters; + + GDMonoClass *delegate = delegates[i]; + + if (_get_signal(top, delegate, parameters)) { + _signals[delegate->get_name()] = parameters; + } + } + + top = top->get_parent_class(); + } + + signals_invalidated = false; } bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector ¶ms) { @@ -1848,6 +1843,8 @@ Ref CSharpScript::create_for_managed_type(GDMonoClass *p_class) { top = top->get_parent_class(); } + script->load_script_signals(script->script_class, script->native); + return script; } @@ -1973,7 +1970,6 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref