# InstantiateGameObjects

> 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.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## InstantiateGameObjects(int, int, NativeArray\<int>, NativeArray\<int>, 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.

> **Warning:**
>
> **Removed.** Obsolete. Please use GameObject.InstantiateGameObjects(EntityId, int, NativeArray\\\<EntityId\\>, NativeArray\\\<EntityId\\>, Scene) instead.

```csharp
public static void InstantiateGameObjects(int sourceInstanceID, int count, NativeArray<int> newInstanceIDs, NativeArray<int> newTransformInstanceIDs, Scene destinationScene = default)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The EntityId of the GameObject to create additional instances of.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of instances of the GameObject to create.**** (\[NativeArray\<int>]\(/engine/6000.5/script-reference/unity/collections/nativearray1)): Pre-allocated NativeArray to populate with the EntityIds of the new GameObjects. Must be the same size as `count`.**** (\[NativeArray\<int>]\(/engine/6000.5/script-reference/unity/collections/nativearray1)): Pre-allocated NativeArray to populate with the EntityIds of the Transforms of the new GameObjects. Must be the same size as `count`.**** (\[Scene]\(/engine/6000.5/script-reference/unityengine/scenemanagement/scene)): The Scene to place the instantiated GameObjects into. If default, then the GameObjects will be added to the currently active Scene.

### Remarks

Use `InstantiateGameObjects` to instantiate multiple GameObjects as a batch. An EntityId can be resolved to an object using [Resources.EntityIdToObject](/engine/6000.5/script-reference/unityengine/resources/entityidtoobject.md).

```csharp
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](/engine/6000.5/script-reference/unityengine/gameobject/setgameobjectsactive.md), [Resources.InstanceIDToObject](/engine/6000.5/script-reference/unityengine/resources/instanceidtoobject.md)

## InstantiateGameObjects(EntityId, int, NativeArray\<EntityId>, NativeArray\<EntityId>, 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.

```csharp
public static void InstantiateGameObjects(EntityId sourceEntityId, int count, NativeArray<EntityId> newEntityIds, NativeArray<EntityId> newTransformEntityIds, Scene destinationScene = default)
```

### Parameters

**** (\[EntityId]\(/engine/6000.5/script-reference/unityengine/entityid)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of instances of the GameObject to create.**** (\[NativeArray\<EntityId>]\(/engine/6000.5/script-reference/unity/collections/nativearray1)): **** (\[NativeArray\<EntityId>]\(/engine/6000.5/script-reference/unity/collections/nativearray1)): **** (\[Scene]\(/engine/6000.5/script-reference/unityengine/scenemanagement/scene)): The Scene to place the instantiated GameObjects into. If default, then the GameObjects will be added to the currently active Scene.

### Remarks

Use `InstantiateGameObjects` to instantiate multiple GameObjects as a batch. An EntityId can be resolved to an object using [Resources.EntityIdToObject](/engine/6000.5/script-reference/unityengine/resources/entityidtoobject.md).

```csharp
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](/engine/6000.5/script-reference/unityengine/gameobject/setgameobjectsactive.md), [Resources.InstanceIDToObject](/engine/6000.5/script-reference/unityengine/resources/instanceidtoobject.md)
