Shootable Set state on impact

snicker

New member
UCC 2.2.5
I want to use shootable weapon impact to set a state on an character's root object to enable presets on CharacterHealth and Character Locomotion as status effects.

When the character is impacted with a shootable weapon, the child game object collider hit(the hitbox referenced by CharacterHealth) has the state activated by shootable's impact.

I can see the state active because I added StateBehavior component to the hitbox collider, but its parent the root Character object does not have the state activated.

This way of setting states with shootable works fine on non-character objects that have their hitbox collider on the same GameObject as the root.

How do I make the root character object copy the same state as its child hitbox colliders? Am I using the StateBehavior component correctly, I think its to share active states between gameObjects?
 

Andrew

Moderator
Staff member
I'm assuming you're using the OnObjectImpact event on the target object, in which case you can juse use StateManager.SetState(gameObject, "StateName", true); Not exactly sure why you're using a StateBehavior component on the character's hitbox.
 

snicker

New member
I put Statebehavior component on there to allow that object to have UCC states, so I could see that the hitbox object was receiving the set state from Shootable Weapon instead of the root object.

I have an Ice themed shootable weapon that inflicts a "Chilled" preset state that slows timescale in CharacterLocomotion for 10 seconds, but the state isn't activated on the root character, only the child collider for 10 sec. It doesn't seem to work how the tooltip for Impact State Name on Shootable Weapon describes it.
 

Attachments

  • UnityGameProjectV2 - OpsiveIntregrationCopyScene - PC, Mac & Linux Standalone - Unity 2019.4.1...png
    UnityGameProjectV2 - OpsiveIntregrationCopyScene - PC, Mac & Linux Standalone - Unity 2019.4.1...png
    34.7 KB · Views: 2
Last edited:

Andrew

Moderator
Staff member
Ok, I was assuming you were using the OnObjectImpact event - it seems that the state set via that setting does only set it on the game object the projectile directly collides with, as you found. You could either use the OnObjectImpact event on the target object to manually set the state when the projectile collides with it, or add a few lines of code to Destructible.cs, starting from line 241:
C#:
                // OLD:
                // An optional state can be activated on the hit object.
                if (!string.IsNullOrEmpty(m_ImpactStateName)) {
                    StateManager.SetState(hitGameObject, m_ImpactStateName, true);
                    ...

                // NEW:
                // An optional state can be activated on the hit object.
                if (!string.IsNullOrEmpty(m_ImpactStateName)) {
                    var locomotion = hitGameObject.GetComponentInParent<UltimateCharacterLocomotion>();
                    if (locomotion != null) {
                        StateManager.SetState(locomotion.gameObject, m_ImpactStateName, true);
                    } else {
                        StateManager.SetState(hitGameObject, m_ImpactStateName, true);
                    }
                    ...
This will search in the impacted object's parent hierarchy until it finds an object with the UltimateCharacterLocomotion component, and set the state on that object instead. I'll pass this on to Justin as a possible addition to a future update.
 
Top