MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Reload

Method Reload

Source/Engine/Scripting/Scripting.cpp:712–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

710#if USE_EDITOR
711
712void Scripting::Reload(bool canTriggerSceneReload)
713{
714 // By default we allow to call it only from the main thread and when no scene is loaded.
715 // Otherwise call scene manager to perform clear scripts reload.
716 // It will call this method back on main thread without scenes loaded, see SceneActionType::ReloadScripts.
717 if (!IsInMainThread() || Level::IsAnySceneLoaded())
718 {
719 if (canTriggerSceneReload)
720 {
721 // Call scene to reload scripts
722 Level::ReloadScriptsAsync();
723 }
724 else
725 {
726 LOG(Warning, "Cannot reload scene on scripting reload. Flag is not set.");
727 }
728 return;
729 }
730
731 PROFILE_CPU();
732
733 // Ideally we would call Release and Load but this would also reload Editor objects which we want avoid
734 // Editor is also referencing assets and other managed objects so we should force reload everything.
735 // However Reload is called when no scene is loaded.
736
737 // Faster path - if no game assembly loaded yet
738 if (!_hasGameModulesLoaded)
739 {
740 // Just load missing assemblies
741 Load();
742 return;
743 }
744
745 LOG(Info, "Start user scripts reload");
746 ScriptsReloading();
747
748 // Destroy objects from game assemblies (eg. not released objects that might crash if persist in memory after reload)
749 ReleaseObjects(true);
750
751 // Unload all game modules
752 LOG(Info, "Unloading game binary modules");
753 auto modules = BinaryModule::GetModules();
754 for (int32 i = modules.Count() - 1; i >= 0; i--)
755 {
756 BinaryModule* module = modules[i];
757 if (module == GetBinaryModuleCorlib() || module == GetBinaryModuleFlaxEngine())
758 continue;
759
760 module->Destroy(true);
761 }
762 modules.Clear();
763 _nonNativeModules.ClearDelete();
764 _hasGameModulesLoaded = false;
765 ManagedDictionary::CachedTypes.Clear();
766
767 // Release and create a new assembly load context for user assemblies
768 MCore::UnloadScriptingAssemblyLoadContext();
769 MCore::CreateScriptingAssemblyLoadContext();

Callers 1

Calls 9

IsInMainThreadFunction · 0.85
ReleaseObjectsFunction · 0.85
GetBinaryModuleCorlibFunction · 0.85
CollectFunction · 0.85
LoadFunction · 0.50
CountMethod · 0.45
DestroyMethod · 0.45
ClearMethod · 0.45
ClearDeleteMethod · 0.45

Tested by

no test coverage detected