I'm having this really weird and frustrating issue and I have no idea why. I have a pool of each particle effect needed for my gunscript to cut down on the amount of instancing that goes on at runtime. For some reason, the first array gets filled with objects meant for a completely different array and leaves the others empty. This is especially strange since I use very similar code for my AI script and it works fine. Here's an example of the code that plays up Code (CSharp): // Particles public GameObject genericHit; public GameObject metalHit; public GameObject bloodHit; // pooling stuff public GameObject[] genericPool; public GameObject[] metalPool; public GameObject[] bloodPool; void Start () { gm = GameObject.Find("GameManager").GetComponent<GameManager>(); wm = this.GetComponentInParent<WeaponManager>(); asource = this.GetComponentInParent<AudioSource>(); // pooling stuff if (this.name == "Pistol") ammoPool = wm.pistolPool; if (this.name == "Rifle") ammoPool = wm.riflePool; if (this.name == "Shotgun") ammoPool = wm.shotgunPool; if (this.name == "MG") ammoPool = wm.mgPool; if (this.name == "Special") ammoPool = wm.specialPool; if (this.name == "Rocket Launcher") ammoPool = wm.rockets; if (this.name == "Grenade Launcher") ammoPool = wm.grenades; PoolingParent = GameObject.Find("GameManager").transform; StartPooling(); // end pooling stuff } // this is the function that plays up void StartPooling () { // Particle effects genericPool = new GameObject[magCapacity]; for (int a = 0; a < genericPool.Length; a++) { GameObject gp = Instantiate(genericHit); gp.transform.parent = PoolingParent; gp.SetActive(false); genericPool[a] = gp; } metalPool = new GameObject[magCapacity]; for (int b = 0; b < metalPool.Length; b++) { GameObject mp = Instantiate(metalHit); mp.transform.parent = PoolingParent; mp.SetActive(false); genericPool[b] = mp; } bloodPool = new GameObject[magCapacity]; for (int c = 0; c < bloodPool.Length; c++) { GameObject bp = Instantiate(bloodHit); bp.transform.parent = PoolingParent; bp.SetActive(false); genericPool[c] = bp; } } A screenshot of the inspector to better illustrate the problem. The following code sample is from my AI script and works perfectly fine, as you can see it's almost identical to the code for before. Code (CSharp): void Start () { life = GetComponent<Health>(); Current_Ammo = Magazine_Capacity; if (faction == Faction.Friend) gameObject.tag = "Friendly"; if (faction == Faction.Enemy) gameObject.tag = "Enemy"; Anim = GetComponent<Animator>(); Nav = GetComponent<NavMeshAgent>(); Limbs = GetComponentsInChildren<Rigidbody>(); Audio = GetComponent<AudioSource>(); for (int i = 0; i < Limbs.Length; i++) { Limbs[i].isKinematic = true; Limbs[i].transform.tag = "Blood"; } Weapon.transform.tag = "Metal"; PoolingParent = GameObject.Find("GameManager").transform; StartPooling(); } void StartPooling () { BulletPool = new GameObject[Magazine_Capacity]; for (int a = 0; a < BulletPool.Length; a++) { GameObject bu = Instantiate(Bullet); bu.transform.parent = PoolingParent; bu.SetActive(false); BulletPool[a] = bu; } CasePool = new GameObject[Magazine_Capacity * 2]; for (int b = 0; b < CasePool.Length; b++) { GameObject ca = Instantiate(Case); ca.transform.parent = PoolingParent; ca.SetActive(false); CasePool[b] = ca; } FlashPool = new GameObject[Magazine_Capacity / 3]; for (int c = 0; c < FlashPool.Length; c++) { GameObject fl = Instantiate(Flash); fl.transform.parent = Muzzle.transform; fl.SetActive(false); FlashPool[c] = fl; } } I really have no idea what is causing the problem.
should be metalPool should be bloodPool copy paste mistake therefore your generic pool hast bloodhits referenced
This has to be the dumbest thing I've done in a long time, I've literally been puzzling at this for hours. Thanks for the help.
Don't worry, you never really stop making these errors. I'm not exaggerating either. You only (hopefully) get faster at spotting them. You might find it useful to invite your dog over and explain it to him, also known as "The Woof Method." See my avatar picture for details. "So here it is Rover, I instantiate the MetalHit, I set its parent, I set it to inactive, then I add it to the ... er, genericPool... okay, thanks Rover, here's a doggie treat... that's a good dog."