If you’re getting the Unity assert: “Assertion failed: Transform has SetIsDispatchInterested present when destroying the hierarchy. Systems must deregister themselves in Deactivate.”
This error is corrected in Unity 2017.3.1p3 (or above). This is happening whenever a collider is disabled on a GameObject which is not currently activeInHierarchy.
Handy piece of code that will run an action on all children of a gameobject.
public static class UnityExtensions
/// Run an action on all children of a gameobject
public static void RunOnChildrenRecursive(this GameObject a_go, Action<GameObject> a_action)
foreach (var child in a_go.GetComponentsInChildren<Transform>(true))
To use it, do something like this: –
myGameObject.RunOnChildrenRecursive(child => child.layer = LayerMask.NameToLayer("UI3D"));