Enemy Death Layer: Children Option

I am trying to use the enemy death layer option to change enemy's layer to something that does not collider with the player character upon death (it really breaks my heart to stomp them around... after I head shot them with a dozen arrows...). Currently it only changes the parent collider, and the sub colliders still keep interacting with the player.

Is there a possibility to add an option to have a sub-check, that can let all the children layers of the enemy to turn into that layer as well?
 
Just adding another vote for this feature. :)

Edit: I see in a different thread that children are supposed to be switching layer on death at least as of 10/2019, but mine are remaining on the subcharacter layer. I've verified that the parent is switching layers as intended. Did I miss a setup step somewhere?
 
Last edited:
Just adding another vote for this feature. :)

Edit: I see in a different thread that children are supposed to be switching layer on death at least as of 10/2019, but mine are remaining on the subcharacter layer. I've verified that the parent is switching layers as intended. Did I miss a setup step somewhere?
I just came to say what you just said @CraigHubbard xD.

You are referring to the Death Layer option on the Health component, correct? I can add this to my feature request list :)
I want the actors of my game to ignore dead bodies on the floor, so I have created a layer (IgnoreActors) that collides with everything except actors' layers like Character or SubCharacter.

This layer is correctly set on the main GameObject of the actor when it dies, but all the childs with rigidbodies have the layer Character. Why those layers are not changed? Am I missing something?

Moreover, I have found that this layer (Character) is set on the Ragdoll Ability, but I don't understand why it is needed after death. I have set IgnoreActors on both layers of Ragdoll (RagdollLayer and InactiveRagdollLayer) and all rigidbodies' layers (childs) are updated correctly, but other actors still can collide with the dead body on the floor. Am I missing something here?


Aleix Cots Molina
 
I believe this is an easy enough feature to add. In Health.cs, add the following code to line 434, so that it looks like this:

C#:
            // Change the layer to a death layer.
            if (m_DeathLayer.value != 0) {
                m_AliveLayer = m_GameObject.layer;
                m_GameObject.layer = m_DeathLayer;
                // NEW CODE START
                foreach (Transform child in m_GameObject.transform) {
                    child.gameObject.layer = m_DeathLayer;
                }
                // NEW CODE END
            }

If you also want all the children's layers to reset back to the original layer, you'll need to do something similar, at line 557:

C#:
            // Change the layer back to the alive layer.
            if (m_DeathLayer.value != 0) {
                m_GameObject.layer = m_AliveLayer;
                // NEW CODE START
                foreach (Transform child in m_GameObject.transform) {
                    child.gameObject.layer = m_AliveLayer;
                }
                // NEW CODE END
            }

But I'll let Justin know, to hopefully add this in to a future update.
 
Thanks for your reply.

I forgot to mention that I already tried to change childs' layers, even all childs that are rigidbodies. However, it does not make a difference because, as I said, the Ragdoll Ability changes all those layers to Character/SubCharacter.
 
I passed it on to Justin and he should be able to implement a fix for that soon, probably in the next update.

I think you may be able to modify Ragdoll for a temporary workaround. The rigidbodys' layers get set on line 130, so you could probably do a similar thing to what I did above, i.e. setting the layer on all child objects of each rigidbody gameobject to m_RagdollLayer (or whatever other layer).
 
Top