| 710 | #if USE_EDITOR |
| 711 | |
| 712 | void 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(); |
no test coverage detected