I come into an issue with wrong assigned layers to spawned prefab.
Setup categories: [Units] -> Spawn on "Default" layer [UI] -> Spawn particles prefabs and static prefabs on UI (NGUI) layer [Fx] - > Spawn particles on a separate camera with separate layer.
For [UI] i spawn the prefabs with PoolBoss.SpawnOutsidePool method and i reparent the item with:
public GameObject HudParent; Transform CastleHUDt = PoolBoss.SpawnOutsidePool("CastleHUD",Vector3.zero,Quaternion.identity); CastleHUD = CastleHUDt.GetComponent<CastleHUD>();
CastleHUDt.parent = HudParent.transform; CastleHUDt.gameObject.layer = HudParent.layer; CastleHUDt.localPosition = Vector3.zero; CastleHUDt.localRotation = Quaternion.identity; CastleHUDt.localScale = Vector3.one; For the rest of items i use PoolBoss.SpawnInPool method. Every prefab in [Fx] category, has attached TimedDespawner script.
Problem: After 5-6 cycles on [Fx] category, prefabs start to get a layer from [UI] items (CastleHUDt.gameObject.layer = HudParent.layer)
The Workaround: At the moment i have to set the layer manually on spawn.
The problem is with prefab getting a wrong layer on spawning. And i can't reproduce this one, it's just come in sometime and only in editor. When deployed to device, i didn't noticed any issues. I should mention that i'm working with unity 2012.2.beta so maybe this behaviour it's not related to PoolBoss and it's something related to unity internals. You can close this thread as not possible to reproduce since i really don't understand what happens.
Hi, So, i narrowed it down to the conclusion: PoolBoss is not ready to work with NGUI. 1. At first spawn cycle, when you spawn a prefab and parent to a NGUI panel, everything it's fine. 2. When you despawn the object, it will get parented back to PoolBoss GameObject but will keep layer and scale from NGUI parent. 3. At second cycle, when you spawn the same item, NGUI will parent the entire hierarchy(including PoolBoss GameObject) to the UI Root(seems that when you parent a widget, NGUI will start to track it) and you get screwed.
The solution is to have a "Don't Reparent" option. And as an improvement, to have a "Spawn on Layer" and "Spawn Scale".
P.S. Another solution is to allow multiple instances of PoolBoss but it will need a redesign of entire component, moved back to PoolManager since it allow this kind of behaviour.