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

Method spawnActor

Source/Engine/Level/Level.cpp:301–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299String Level::Layers[32];
300
301bool LevelImpl::spawnActor(Actor* actor, Actor* parent)
302{
303 if (actor == nullptr)
304 {
305 Log::ArgumentNullException(TEXT("Cannot spawn null actor."));
306 return true;
307 }
308
309 if (actor->GetType().ManagedClass->IsAbstract())
310 {
311 Log::Exception(TEXT("Cannot spawn abstract actor type."));
312 return true;
313 }
314
315 if (actor->Is<Scene>())
316 {
317 // Spawn scene
318 actor->InitializeHierarchy();
319 actor->OnTransformChanged();
320 {
321 SceneBeginData beginData;
322 actor->BeginPlay(&beginData);
323 beginData.OnDone();
324 }
325 CallSceneEvent(SceneEventType::OnSceneLoaded, (Scene*)actor, actor->GetID());
326 }
327 else
328 {
329 // Spawn actor
330 if (Level::Scenes.IsEmpty())
331 {
332 Log::InvalidOperationException(TEXT("Cannot spawn actor. No scene loaded."));
333 return true;
334 }
335 if (parent == nullptr)
336 parent = Level::Scenes[0];
337
338 actor->SetPhysicsScene(parent->GetPhysicsScene());
339 actor->SetParent(parent, true, true);
340 }
341
342 return false;
343}
344
345bool LevelImpl::deleteActor(Actor* actor)
346{

Callers

nothing calls this directly

Calls 13

InitializeHierarchyMethod · 0.80
OnDoneMethod · 0.80
GetIDMethod · 0.80
SetPhysicsSceneMethod · 0.80
GetPhysicsSceneMethod · 0.80
ExceptionClass · 0.50
GetTypeMethod · 0.45
OnTransformChangedMethod · 0.45
BeginPlayMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected