Managing Attached Effects
Since effects can be parented to objects as a means of attaching them, special care must be taken when managing the pooled effect objects. When an object with effects attached to it gets destroyed, we don't want the effects attached to it to be destroyed as well. This is what the Impact Attached Effect Manager component is for.
Any object that an effect attaches to needs an Impact Attached Effect Manager component. This script is responsible for keeping track of all of the effects attached to an object. If the object does not already have this component, it will be automatically added. However, you can manually add the component yourself by going to . You have some flexibility as to where you can add this component. For example, if you have a character or a ragdoll that will recieve decals, you can add the Impact Attached Effect Manager component to the root of the character, rather than adding a component to each part of the armature.
The Impact Attached Effect Manager also has a small API you can use if you need to manually manage attached effects. Most notable is the ReleaseAllAttachedEffects method, which will release all effects attached to the object and return them to their object pools.
public void DestroyObjectExample(GameObject go) { //Release all effects before destroying the object. if(go.TryGetComponent(out ImpactAttachedEffectManager impactAttachedEffectManager)) { impactAttachedEffectManager.ReleaseAllAttachedEffects(); } //Now you can safely destroy the object. Destroy(go) }
If the object is destroyed, the Impact Attached Effect Manager will automatically move all of the attached effects back into their pools so that they are not also destroyed. However, this does not work on scene load and the effects will still be destroyed. If this happens, the effect object pools will automatically re-instantiate the destroyed effects on scene load. If you want to avoid re-creating effects, it is a good idea to reset all effects back to their object pools before you load a scene. To do this, you can call the ResetAllEffectProcessors on ImpactCFXGlobal or ImpactCFXManager
public void LoadSceneExample(int sceneIndex) { //Reset all effects before loading the new scene. //This will ensure that any attached effects will be returned to their object pools, preventing them from being destroyed. ImpactCFXGlobal.ResetAllEffectProcessors() //Now you can safely load the scene. SceneManager.LoadScene(sceneIndex); }