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

Method Spawn

Source/Editor/Modules/SceneEditingModule.cs:332–378  ·  view source on GitHub ↗

Spawns the specified actor to the game (with undo). The actor. The parent actor. Set null as default. The order under the parent to put the spawned actor. True if automatically select the spawned actor, otherwise false.

(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true)

Source from the content-addressed store, hash-verified

330 /// <param name="orderInParent">The order under the parent to put the spawned actor.</param>
331 /// <param name="autoSelect">True if automatically select the spawned actor, otherwise false.</param>
332 public void Spawn(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true)
333 {
334 bool isPlayMode = Editor.StateMachine.IsPlayMode;
335
336 if (Level.IsAnySceneLoaded == false)
337 throw new InvalidOperationException("Cannot spawn actor when no scene is loaded.");
338
339 SpawnBegin?.Invoke();
340
341 // During play in editor mode spawned actors should be dynamic (user can move them)
342 if (isPlayMode)
343 actor.StaticFlags = StaticFlags.None;
344
345 // Add it
346 Level.SpawnActor(actor, parent);
347
348 // Set order if given
349 if (orderInParent != -1)
350 actor.OrderInParent = orderInParent;
351
352 // Peek spawned node
353 var actorNode = Editor.Instance.Scene.GetActorNode(actor);
354 if (actorNode == null)
355 throw new InvalidOperationException("Failed to create scene node for the spawned actor.");
356
357 // Call post spawn action (can possibly setup custom default values)
358 actorNode.PostSpawn();
359
360 // Create undo action
361 IUndoAction action = new DeleteActorsAction(actorNode, true);
362 if (autoSelect)
363 {
364 var before = Selection.ToArray();
365 Selection.Clear();
366 Selection.Add(actorNode);
367 OnSelectionChanged();
368 action = new MultiUndoAction(action, new SelectionChangeAction(before, Selection.ToArray(), OnSelectionUndo));
369 }
370 Undo.AddAction(action);
371
372 // Mark scene as dirty
373 Editor.Scene.MarkSceneEdited(actor.Scene);
374
375 SpawnEnd?.Invoke();
376
377 OnDirty(actorNode);
378 }
379
380 /// <summary>
381 /// Converts the selected actor to another type.

Callers 1

Calls 8

SpawnActorMethod · 0.80
GetActorNodeMethod · 0.80
AddActionMethod · 0.80
PostSpawnMethod · 0.45
ToArrayMethod · 0.45
ClearMethod · 0.45
AddMethod · 0.45
MarkSceneEditedMethod · 0.45

Tested by

no test coverage detected