seb33
New Member
Posts: 17
Posts: 17
|
Post by seb33 on Feb 9, 2017 16:04:19 GMT
Apologies if this is a dumb question, am not even sure if coregamekit is the right tool for this job. I am instantiating many enemies but they have some characteristics that cannot be known before runtime (e.g spawn location). Currently I end up with a huge array that then instantiates many enemies at once, but I would prefer to add them to a pooling solution and then let coregamekit take care the wave timings. Is this possible and how do I 'hook into' the API? Any help much appreciated. Thanks.
|
|
|
Post by DarkTonic Dev on Feb 9, 2017 17:45:16 GMT
Yes this is possible. We have 2 types of spawners, Triggered and Syncro. That will determine the spawn location, and have many other options (timing too).
You don't actually need to use any API if you use the spawners, it takes zero coding. If you want to spawn / despawn things from the pool with code, yes you can do that too with single lines of code.
Things that spawn, if they need code to "initialize" state each time they spawn, will do so in a special method called OnSpawned, not Awake or Start.
|
|
seb33
New Member
Posts: 17
Posts: 17
|
Post by seb33 on Feb 9, 2017 19:17:31 GMT
Thanks for the reply. Am just having a hard time figuring out how to pass the data to coregamekit.
GameObject go = GameObject.Instantiate(enemyprefab); go.transform.localPosition = coordinates.convertCoordinateToVector(0); go.transform.parent = transform; go.name = (string)enemy.category; NewEnemy newenemy = go.GetComponent<NewEnemy>(); newenemy.category = category; The location and category of the enemy is not known before runtime.
|
|
|
Post by DarkTonic Dev on Feb 9, 2017 19:29:06 GMT
First, you cannot change the name of the game object when using Pool Boss, or it won't know where to despawn to (game object name is used and must match prefab name that has been previously set up in Pool Boss).
Anyway, instead of Instantiate, do this:
var spawnedTransform = PoolBoss.Spawn(enemyprefab, locationVector3, Quaternion.Identity, parentTransformIfAny);
|
|
seb33
New Member
Posts: 17
Posts: 17
|
Post by seb33 on Feb 9, 2017 19:40:38 GMT
Aha, I get it!! Thanks a million
|
|
seb33
New Member
Posts: 17
Posts: 17
|
Post by seb33 on Feb 9, 2017 21:19:16 GMT
Eek sorry,
var spawnedTransform = PoolBoss.Spawn(enemyprefab, locationVector3, Quaternion.identity, transform.parent); is giving me: Argument 1: cannot convert from 'UnityEngine.GameObject' to 'UnityEngine.Transform'
Should I be looking at using PoolBoss.SpawnInPool instead??
|
|
|
Post by DarkTonic Dev on Feb 9, 2017 22:50:19 GMT
No, pass in the transform of the prefab instead of the game object as the first parameter.
I.e.
Enemyprefab.transform
|
|
seb33
New Member
Posts: 17
Posts: 17
|
Post by seb33 on Feb 10, 2017 0:09:07 GMT
Brill, I added
var go = UnityEngine.Object.FindObjectOfType<NewEnemy>(); after setting the transform so that I could add data to the individual enemies (not sure if thats efficient), and it's all working
Thanks again!
|
|
|
Post by DarkTonic Dev on Feb 10, 2017 0:24:45 GMT
Brill, I added var go = UnityEngine.Object.FindObjectOfType<NewEnemy>(); after setting the transform so that I could add data to the individual enemies (not sure if thats efficient), and it's all working Thanks again! FindObjectByType can be quite slow when there are a lot of objects in your Scene, as is easy to happen when using a Pooling plugin with lots of clones of each prefab. Instead I would probably maintain a list of the spawned enemies in some kind of static class and use that list directly to add data. But if it's still fast, no need to do that right now. -Brian
|
|