Add SpawnOptions container for more robust prefabs spawning

This commit is contained in:
Wojtek Figat
2025-01-20 23:50:47 +01:00
parent 86444aa5f3
commit 18fd68db25
3 changed files with 113 additions and 50 deletions

View File

@@ -102,6 +102,30 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
/// <returns>The created actor (root) or null if failed.</returns>
static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, SceneObject*, HeapAllocation>* objectsCache, bool withSynchronization = true);
struct FLAXENGINE_API SpawnOptions
{
// Spawn transformation.
const Transform* Transform = nullptr;
// The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.
Actor* Parent = nullptr;
// Custom objects mapping (maps prefab objects into spawned objects).
const Dictionary<Guid, Guid, HeapAllocation>* IDs = nullptr;
// Output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).
Dictionary<Guid, SceneObject*, HeapAllocation>* ObjectsCache = nullptr;
// if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.
bool WithSync = true;
// True if linked spawned prefab objects with the source prefab, otherwise links will be valid only for nested prefab objects.
bool WithLink = true;
};
/// <summary>
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
/// </summary>
/// <param name="prefab">The prefab asset.</param>
/// <param name="options">The spawn options container.</param>
/// <returns>The created actor (root) or null if failed.</returns>
static Actor* SpawnPrefab(Prefab* prefab, const SpawnOptions& options);
#if USE_EDITOR
/// <summary>