| Parameter | Description |
|---|---|
| sourceInstanceID | The EntityId of the GameObject to create additional instances of. |
| count | The number of instances of the GameObject to create. |
| newInstanceIDs | Pre-allocated NativeArray to populate with the EntityIds of the new GameObjects. Must be the same size as count. |
| newTransformInstanceIDs | Pre-allocated NativeArray to populate with the EntityIds of the Transforms of the new GameObjects. Must be the same size as count. |
| destinationScene | The Scene to place the instantiated GameObjects into. If default, then the GameObjects will be added to the currently active Scene. |
Creates a specified number of instances of a GameObject identified by its instance ID and populates NativeArrays with the EntityIds of the new GameObjects and their Transform components.
Use InstantiateGameObjects to instantiate multiple GameObjects as a batch. An EntityId can be resolved to an object using Resources.EntityIdToObject.
using System; using Unity.Collections; using UnityEngine;
public class InstantiateEntityId : MonoBehaviour { public GameObject prefab; public int count = 100;
EntityId m_EntityId; NativeArray<EntityId> m_EntityIds; NativeArray<EntityId> m_TransformIds; void Start() { m_EntityId = prefab.GetEntityId(); m_EntityIds = new NativeArray<EntityId>(count, Allocator.Persistent); m_TransformIds = new NativeArray<EntityId>(count, Allocator.Persistent);
GameObject.InstantiateGameObjects(m_EntityId, count, m_EntityIds,m_TransformIds ); }
void OnDestroy() { m_EntityIds.Dispose(); m_TransformIds.Dispose(); } }
Additional resources: GameObject.SetGameObjectsActive, Resources.InstanceIDToObject