bryano
New Member
Posts: 9
Posts: 9
|
Post by bryano on Oct 23, 2017 21:32:23 GMT
for (j = 0; j < weaponSettings.projectilePosition.Count; j++) {
for (int l = 0; l < weaponSettings.projectilesPerShoot; l++) {
//create the projectile
GameObject projectile = (GameObject)Instantiate (weaponProjectile, weaponSettings.projectilePosition [j].position, weaponSettings.projectilePosition [j].rotation);
to
GameObject projectile = PoolBoss.SpawnInPool(weaponProjectile, weaponSettings.projectilePosition [j].position, weaponSettings.projectilePosition [j].rotation);
Fails-
How do I use the pool spawner syntax here?
|
|
|
Post by DarkTonic Dev on Oct 23, 2017 22:00:57 GMT
Yes it does replace, but Instantiate uses GameObjects. We use Transforms only (input and output). If you actually need the GameObject as an output (which is unusual), do .GetComponent<GameObject>() on it after. First parameter should be weaponProjectile.GetComponent<Transform>().
|
|
bryano
New Member
Posts: 9
Posts: 9
|
Post by bryano on Oct 24, 2017 11:17:37 GMT
TY I didnt write the code in this project - and I dont want to touch it anymore than to insert your pooling commands into it replacing all destroy and instantiate calls.
So its this instead?
Transform weaponProjectilet = weaponProjectile.GetComponent<Transform> ();
//create the projectile
Transform projectilet = PoolBoss.SpawnInPool(weaponProjectilet, weaponSettings.projectilePosition [j].position, weaponSettings.projectilePosition [j].rotation);
GameObject projectile = projectilet.GetComponent<GameObject> ();
Which leads me to another question:
Is there a way to intercept instantiate and destroy globally? Instead of tracking down every call?
I have bullets and muzzle flashes and shells and impact particles and blood and bullet scorch marks to pool - so...
it would be easier if there was a method to intercept or override globally all destroy and instantiate calls project wide and route them to your methods- is there?
Also: If a "Spawn" call is made via script as above the object's prefab is automagically entered into the pool at the first instance?
Finally: - How does pooling work between concurrently running scenes - is it better to parent them all via "SpawnInPool" and keep all pooled objects in the same scene?
|
|
|
Post by DarkTonic Dev on Oct 24, 2017 16:24:32 GMT
Looks correct. You technically should check is projectilet is non-null before doing a GetComponent on it. It can be null if something didn't spawn (item limit reached previously).
No, there's no way to intercept. You'll need to find all of them with a global search (CTRL+SHIFT+F in Visual Studio).
If you turn on "auto-add missing items" then anything spawned will have a pool item created, but that's generally a bad idea since that is Instantiated to get in there.
I don't understand the last question, but generally we do one LevelSettings game object per Scene and despawn everything before going to next Scene.
|
|
bryano
New Member
Posts: 9
Posts: 9
|
Post by bryano on Oct 25, 2017 2:41:39 GMT
Loading content asynchronously to create streaming content requires multiple scenes to be open at the same time.
Im still figuring out how all of this works and wondered about interaction between scenes and pool boss.
To update you I entered the syntax we discussed and loaded the prefabs into the pool boss but my bullets aren't appearing when I shoot.
There are no errors in the console - so right now Im a bit stumped.
|
|
|
Post by DarkTonic Dev on Oct 25, 2017 3:29:19 GMT
I have no idea how that works (having multiple scenes open at the same time). I would think that each of those scenes would need their own Pool Boss, no?
|
|
bryano
New Member
Posts: 9
Posts: 9
|
Post by bryano on Oct 25, 2017 14:52:06 GMT
I was hoping you, being the coding genius who wrote the thing, could tell me. Calling scripts on objects between scenes has been problematic and I've been getting odd results. I was hoping putting spawns under the pool boss object would be the solution as then they would all be instanced in the same scene and at least between them there would be no cross scene talk. I've been putting Pool Boss in the "meta-scene" which is created when you set an object to not be destroyed when it's originating scene is unloaded. But even though the spawning object of the bullets lives there too "no worky". docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
|
|
|
Post by DarkTonic Dev on Oct 25, 2017 16:08:24 GMT
Thanks for the compliment, but it's not going to suddenly give me the knowledge I need to answer you  I suggest you ask this question on the Unity forums. It doesn't really have to require Pool Boss. Just "how do you access a single game object in all simultaneously open scenes that's in the Hierarchy?" Surely someone knows. My games only use a single Scene at a time.
|
|
bryano
New Member
Posts: 9
Posts: 9
|
Post by bryano on Oct 25, 2017 19:58:59 GMT
thanks
|
|
|
Post by DarkTonic Dev on Oct 25, 2017 20:21:05 GMT
Any time, sorry I wasn't able to help more. If you do find a solution, post it back here in case anyone else runs in the same problem. I'm interested to know as well.
|
|