Skip to content

Commit da43439

Browse files
committed
Fixed SetParent() for objects created in runtime.
1 parent 748f830 commit da43439

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

EC_ObjectPooling.unitypackage

5 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

EngyneCreations/ObjectPooling/Demo/Scripts/EC_BulletStartDemo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void Start () {
3030
InvokeRepeating("SpawnNew", 0, fireTime);
3131
}
3232

33-
// Retrieve from the object pool, check if null and reset the position and rotation.
33+
// Retrive from the object pool, check if null, reset position and rotation and set active.
3434
void SpawnNew() {
3535

3636
GameObject obj = emitter.Generate();
@@ -39,5 +39,6 @@ void SpawnNew() {
3939

4040
obj.transform.position = transform.position;
4141
obj.transform.rotation = transform.rotation;
42+
obj.SetActive(true);
4243
}
4344
}

EngyneCreations/ObjectPooling/Scripts/EC_ObjectPoolEmitter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public GameObject Generate() {
2828

2929
obj.SetActive(true);
3030

31-
if (EC_ObjectPooling.instance.pool[index].customParent != null) {
32-
obj.transform.SetParent(EC_ObjectPooling.instance.pool[index].customParent, true);
33-
}
3431
return obj;
3532
}
3633
}

EngyneCreations/ObjectPooling/Scripts/EC_ObjectPooling.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ void Start () {
4040
for (int p = 0; p < pool[i].startAmount; p++) {
4141
GameObject obj = Instantiate(pool[i].poolObject);
4242
obj.SetActive(false);
43+
44+
if (pool[i].customParent) {
45+
obj.transform.SetParent(pool[i].customParent, true);
46+
}
47+
4348
pool[i].poolList.Add(obj);
4449
}
4550
}
@@ -70,6 +75,11 @@ public GameObject GetPooledObject(int index) {
7075

7176
if (pool[index].canGrow) {
7277
GameObject obj = Instantiate(pool[index].poolObject);
78+
79+
if (pool[index].customParent) {
80+
obj.transform.SetParent(pool[index].customParent, true);
81+
}
82+
7383
pool[index].poolList.Add(obj);
7484
return obj;
7585
}

0 commit comments

Comments
 (0)