| 1117 | } |
| 1118 | |
| 1119 | SceneResult SceneLoader::OnBegin(Args& args) |
| 1120 | { |
| 1121 | PROFILE_CPU_NAMED("Begin"); |
| 1122 | LOG(Info, "Loading scene..."); |
| 1123 | _lastSceneLoadTime = DateTime::Now(); |
| 1124 | StartFrame = Engine::UpdateCount; |
| 1125 | |
| 1126 | // Validate arguments |
| 1127 | if (!args.Data.IsArray()) |
| 1128 | { |
| 1129 | LOG(Error, "Invalid Data member."); |
| 1130 | CallSceneEvent(SceneEventType::OnSceneLoadError, nullptr, Guid::Empty); |
| 1131 | return SceneResult::Failed; |
| 1132 | } |
| 1133 | |
| 1134 | // Peek scene node value (it's the first actor serialized) |
| 1135 | SceneId = JsonTools::GetGuid(args.Data[0], "ID"); |
| 1136 | if (!SceneId.IsValid()) |
| 1137 | { |
| 1138 | LOG(Error, "Invalid scene id."); |
| 1139 | CallSceneEvent(SceneEventType::OnSceneLoadError, nullptr, SceneId); |
| 1140 | return SceneResult::Failed; |
| 1141 | } |
| 1142 | |
| 1143 | // Peek meta |
| 1144 | if (args.EngineBuild < 6000) |
| 1145 | { |
| 1146 | LOG(Error, "Invalid serialized engine build."); |
| 1147 | CallSceneEvent(SceneEventType::OnSceneLoadError, nullptr, SceneId); |
| 1148 | return SceneResult::Failed; |
| 1149 | } |
| 1150 | Modifier->EngineBuild = args.EngineBuild; |
| 1151 | |
| 1152 | // Scripting backend should be loaded for the current project before loading scene |
| 1153 | if (!Scripting::HasGameModulesLoaded()) |
| 1154 | { |
| 1155 | LOG(Error, "Cannot load scene without game modules loaded."); |
| 1156 | #if USE_EDITOR |
| 1157 | if (!CommandLine::Options.Headless.IsTrue()) |
| 1158 | { |
| 1159 | if (ScriptsBuilder::LastCompilationFailed()) |
| 1160 | MessageBox::Show(TEXT("Script compilation failed.\n\nCannot load scene without game script modules. Please fix any compilation issues.\n\nSee Output Log or logs for more info."), TEXT("Failed to compile scripts"), MessageBoxButtons::OK, MessageBoxIcon::Error); |
| 1161 | else |
| 1162 | MessageBox::Show(TEXT("Failed to load scripts.\n\nCannot load scene without game script modules.\n\nSee logs for more info."), TEXT("Missing game modules"), MessageBoxButtons::OK, MessageBoxIcon::Error); |
| 1163 | } |
| 1164 | #endif |
| 1165 | CallSceneEvent(SceneEventType::OnSceneLoadError, nullptr, SceneId); |
| 1166 | return SceneResult::Failed; |
| 1167 | } |
| 1168 | |
| 1169 | // Skip is that scene is already loaded |
| 1170 | if (Level::FindScene(SceneId) != nullptr) |
| 1171 | { |
| 1172 | LOG(Info, "Scene {0} is already loaded.", SceneId); |
| 1173 | CallSceneEvent(SceneEventType::OnSceneLoadError, nullptr, SceneId); |
| 1174 | return SceneResult::Failed; |
| 1175 | } |
| 1176 |
no test coverage detected