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

Method OnSpawn

Source/Engine/Level/Level.cpp:1189–1247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1187}
1188
1189SceneResult SceneLoader::OnSpawn(Args& args)
1190{
1191 PROFILE_CPU_NAMED("Spawn");
1192
1193 // Get any injected children of the scene.
1194 InjectedSceneChildren = Scene->Children;
1195
1196 // Allocate scene objects list
1197 SceneObjects = ActorsCache::SceneObjectsListCache.GetUnscoped();
1198 const int32 dataCount = (int32)args.Data.Size();
1199 SceneObjects->Resize(dataCount);
1200 SceneObjects->At(0) = Scene;
1201 AsyncJobs &= dataCount > 10;
1202
1203 // Spawn all scene objects
1204 Context.Async = AsyncJobs;
1205 SceneObject** objects = SceneObjects->Get();
1206 if (Context.Async)
1207 {
1208 Level::ScenesLock.Unlock(); // Unlock scenes from Main Thread so Job Threads can use it to safely setup actors hierarchy (see Actor::Deserialize)
1209 JobSystem::Execute([&](int32 i)
1210 {
1211 PROFILE_MEM(Level);
1212 i++; // Start from 1. at index [0] was scene
1213 auto& stream = args.Data[i];
1214 auto obj = SceneObjectsFactory::Spawn(Context, stream);
1215 objects[i] = obj;
1216 if (obj)
1217 {
1218 if (!obj->IsRegistered())
1219 obj->RegisterObject();
1220#if USE_EDITOR
1221 // Auto-create C# objects for all actors in Editor during scene load when running in async (so main thread already has all of them)
1222 if (!obj->GetManagedInstance())
1223 obj->CreateManaged();
1224#endif
1225 }
1226 else
1227 SceneObjectsFactory::HandleObjectDeserializationError(stream);
1228 }, dataCount - 1);
1229 Level::ScenesLock.Lock();
1230 }
1231 else
1232 {
1233 for (int32 i = 1; i < dataCount; i++) // start from 1. at index [0] was scene
1234 {
1235 auto& stream = args.Data[i];
1236 auto obj = SceneObjectsFactory::Spawn(Context, stream);
1237 objects[i] = obj;
1238 if (obj)
1239 obj->RegisterObject();
1240 else
1241 SceneObjectsFactory::HandleObjectDeserializationError(stream);
1242 }
1243 }
1244
1245 NextStage();
1246 return SceneResult::Success;

Callers

nothing calls this directly

Calls 10

GetUnscopedMethod · 0.80
UnlockMethod · 0.80
LockMethod · 0.80
SpawnFunction · 0.50
SizeMethod · 0.45
ResizeMethod · 0.45
GetMethod · 0.45
RegisterObjectMethod · 0.45
GetManagedInstanceMethod · 0.45
CreateManagedMethod · 0.45

Tested by

no test coverage detected