How to Disable Use ability while Blocking/Potential Blocking Bug

Edit: I think I do have the state system working after other tests.. So it may likely be more to do with my 2nd follow up post.

Hello.

I am new to the Opsive world and I have UCC and UIS and am working in third person. So far I have been able to work out everything quite well through the documentation as it is very well written. I am getting a little stuck with a particular part in which seems to also be the case in the demo so I have come here for help.

While using a melee sword, I have the block item ability working successfully as well as the counter-attack. I can not seem to figure out how to make the character not be blocking while performing the item use function (attack). So long as I am aiming and facing the character I am invincible (or whatever the set damage in the shield component is). This is the same in the third-person demo in the counter-attack section. So long as I am aiming I am blocking even if Nolan is swinging the sword at the same time. I was hoping seeing it in action in the demo it would clear it up but I now wonder if it can be done that way.

I believe based on what I have been reading that this would likely have something to do with the state system? I have watched the video and read the documentation but I can't seem to get it right.

So in short, could you help me understand how I can deactivate the Block item ability while the Use item ability is active? It seems like it should be so simple but my brain is just not connecting the dots for some reason. There always has to be something haha.

I am sure if I understand this I will have a much greater understanding on a larger scale as I seem to get everything else but this and it can get quite complex.

Sorry for the long-winded explanation.

Thank you.
 
Last edited:
Actually, on further testing. So long as I am aiming my weapon I don't seem to be taking any damage at all regardless of the "absorption factor" or if I have the Block item ability completely unselected. The same is also the case in the demo. I turned off Nolan's Block ability and with the sword while aiming at the "Counter Attack Agent" I was receiving no damage so long as I am facing the agent with the Aim ability active.

So I may have actually worked out the state system fine but I can not quite tell. It may be something more?
 
Last edited:
I believe this is to do with the colliders on the items. If you're aiming with the sword/shield then those items' colliders will be in front of the character's body, so when an another item tries to collide with the player, it'll hit the held item first and never actually collide with the player itself. So you probably want to consider changing the items' layers to a layer that doesn't collide with the incoming attacking items.
 
Thank you for your response. Unfortunately, I did not get any positive results from changing the layer on the item from SubCharacter as is by default. In fact, I seem to lose control of the character and things move very oddly while the weapon is equiped. I tried this on the weapon prefab and on the sword attached to Nolan in the demo. Both had the same outcome. I also tried this on just the collider part of my item prefab and it was the same.

I figured it must be collider-related but considering the "absorb" feature I thought there must be a method within the components.

Would there be a more specific approach you are suggesting? If it does not work that way in the demo, how is the feature supposed to be used to get the absorption results and whatnot? I suppose I'm stuck as to whether it's me or the system does not currently do it as I can't seem to see it in action anywhere to reference. Sorry again, I have spent many hours on this and at some point, I need to wonder if it's me or the controller.

I thought that maybe it only activates the collider on Use or on Block, but I guess how would it know to block unless the collider is active to know it's had a collision... ect. I'm a little stuck haha.

Thank you.
 
Last edited:
It does sound like using the state system is the right approach. When the Use ability is active you should have the Block ability disabled. Are you sure that it is the block ability stopping the attack, though? If you have a Shield ItemAction attached to the melee weapon then that Shield will also block the attack. One way to definitively say the cause is to place a breakpoint within MeleeWeapon.HitCollider to see if the full damageAmount is being sent to hitHealth.Damage.
 
Okay thank you, I can understand that the shield component on the melee weapon could be what is causing the issue. But when I take the shield component off, the block ability on the weapon no longer activates. In the documentation, it says both are required. So does this mean that even if I deactivate the block ability with the state system the shield component will always block the damage anyway while aiming?

If I turn the shield component off I take damage as usual but there is no block. If it is on, I will not take damage at all while aiming even if the absorption is set to 0 or 1 and block does activate. The absorption may be a separate issue with the shield component altogether as it doesn't seem to affect anything anyway. This issue also exists within the demo. Is that what this function is supposed to do?

I am not quite sure what you mean by adding a breakpoint sorry. Are you referring to coding? Because I will need further assistance with that if so I am not a strong coder, I can just read and follow documentation well.

In the state system of the shield, I tried to see if there was a way I could deactivate the shield itself while Use was active but this does not seem to be possible either. Just for curiosity, I attempted this with the absorption factor but since that wasn't correctly working anyway I was not able to notice any results.

My main issue is so far as long as I want to use the block ability or parry ability on my melee weapon (which I very much do), I can not without the character being invincible so long as the shield component is going to always be active while aiming, and the shield component is required for the character to block. This interrupts the aim lock-on system too. While locked on you are also invincible and can just slash away risk-free, making the blocking and parry attacking redundant and just animations going off. So I know they work, but they don't serve their purpose. Again this is the same case in the demo scene.

I may be missing a loophole here but I have been going over the docs and this seems to be a wall in the system I can't get over. How do you block without the shield component?

I guess after everything I am trying I am just wondering if it is possible to do currently?
 
Last edited:
I still think this is a collider thing, not related to the Shield component. Even in the demo scene, if you get hit by the agent whilst not aiming, in third person view the damage goes through fine because the sword hits the character's capsule collider, but in first person the sword is held directly in front of the player and the agent's sword always hits the player's sword, so no Health component is found and damage is never applied, regardless of the Shield component.

If so, I believe a small addition to the MeleeWeapon component fixes this (at least it seems to do so in the demo scene):

C#:
        public void HitCollider(MeleeHitbox hitbox, RaycastHit raycastHit, GameObject hitGameObject, Collider hitCollider, Health hitHealth)
        {
            // The shield can absorb some (or none) of the damage from the melee attack.
            var damageAmount = m_DamageAmount * hitbox.DamageMultiplier;
            ShieldCollider shieldCollider;
            if ((shieldCollider = hitGameObject.GetCachedComponent<ShieldCollider>()) != null) {
                // START NEW CODE
                if (hitHealth == null) {
                    hitHealth = shieldCollider.Shield.transform.GetComponentInParent<Health>();
                }
                // END NEW CODE
                var shieldDamageAmount = shieldCollider.Shield.Damage(this, damageAmount);
                m_SolidObjectHit = m_ApplyRecoil && damageAmount != shieldDamageAmount;
                damageAmount = shieldDamageAmount;
            } else if (hitGameObject.GetCachedComponent<RecoilObject>() != null) {
                m_SolidObjectHit = m_ApplyRecoil;
            }
            ...
        }

Those new lines will find the character's Health component if the struck object has the ShieldCollider component (and the Shield property is correctly set to the item's Shield component).

If this does indeed solve the issue, @Justin - possible future update?
 
Thanks so much for this detailed response. I will check it when I get home from work but everything you are saying makes absolute sense and would seemingly be the problem. I will let you know how it goes. Either way, I appreciate this being looked into.

Cheers.
 
Unfortunately, I am still not noticing any improvements with the extra line of code.

I tried it in a fresh project only using TPC 2.3.1 and Unity 2019.4.16f1. If I am aiming and rapidly swinging away I will still not lose damage regardless of the absorption factor being at 0 so long as I am directly facing the enemy and holding aim, also the case when I turn off the block ability (with absorption at 0) and not swinging. It does not seem to matter what direction the sword is in when I am hit. I can see the occasional blood decal appear to indicate that there must be an impact of some sort but no health or damage indication occurs.

Thanks again for looking into this. I hate to be a bother but if it's a feature not working correctly I hope this is more helpful than a hindrance.

EDIT: So just FYI, I have managed to wrangle together a system using the attribute manager that still remains cohesive with my game so the character can have an invulnerable block but only as long as the item's block durability lasts. When it's empty the state system disables the block ability on character damage visualization which will activate when the block attribute hits 0 until it replenishes over time. I do think it would be amazing to have the system working as has been discussed as this has its kinda messy flaws but in the meantime this is acceptable. I would be very interested in knowing if this progresses in the future though. In the meantime, I can continue with my game utilizing the desired features so I am at least no longer hitting a wall. This method may help anyone else in a similar position.
I am happy to keep working on finding the fix so long as you are though. It really would be a great system to have working as originally planned.
 
Last edited:
It does not seem to matter what direction the sword is in when I am hit. I can see the occasional blood decal appear to indicate that there must be an impact of some sort but no health or damage indication occurs.
So even if your back is turned to the enemy? I'm assuming the sword's collider doesn't even get hit in that case, but you could check by logging the value of hitCollider or hitGameObject at the top of MeleeWeapon.HitCollider. If it's hitting your character and still not applying the damage then the issue is not even with the sword item itself. Does this issue occur when you don't even have the sword equipped? I'd recommend putting maybe a few logs near the top of HitCollider, e.g. for hitCollider/hitGameObject, shieldCollider, hitHealth, damageAmount just to see exactly what object is being hit, if there is any damage absorption actually going on, etc.
 
Oh no, if you are hit from the side or any other direction it damages fine. It's only when facing front on. The main issue is that so long as you are facing them directly you can swing away and never be damaged or if you are Locked On (as is in my game) especially with the Orbit Target ability then you are basically always facing them and as long as you're aiming they can't hurt you (though decals may appear). In the demo, it's not hard to maintain a front-on position. The shield component itself does not seem to change the amount of damage taken regardless of the absorb.

With the sword, if you go into the demo and hold right-click while facing the target in the melee room just keep attacking or facing them head-on while they attack and you should easily see what I mean. I will capture a video but it should be very obvious on gameplay what I mean.
 
Last edited:
Here. Watch this or try it yourself:


At the start, you can see I am holding aim and I can slash away and nothing will happen to me so long as I am directly facing the target. When I stop aiming I take damage, from another direction I take damage. When I aim again (and face the target) I am invincible. If you look to the right you will see the shield absorption is set to 0. If you deactivate the block ability it does not change anything. I have been mentioning a bunch of issues but I assume it stems from here.

Example 2: No block ability active, absorption set to 0, could just stand there all day so long as you face them.


The main problem remains that so long as you are facing them and aiming the shield makes you invincible so in a melee fight even when attacking you are shielding so long as you are aiming, making the fight... not much of a fight. If you go further and are locked on and orbiting, you can't be hit so long as you are aiming (which is required to activate the lock on). Also if I wanted to have the block take stamina (or whatever) and not be able to block when out of stamina, it doesn't matter because you will be constantly shielded anyway. By setting durability to the shield it prevents permanent invulnerability but you can still shield while attacking simultaneously so long as it's durable.

I hope this clears up what I am trying to say :)

I suppose I could be using the system not as intended but I guess I just assumed this was how it was supposed to work based on other melee combat.


PS: Sorry I can't be bothered waiting for the light to bake so it's a bit darker than usual.
 
Last edited:
Have you tried my suggestions above? The reason this is happening is almost certainly because when the sword is in front of the character (when aiming or attacking) it intercepts the enemy's attack, i.e. the enemy's sword collides with the character's sword instead of the character collider itself. If you can verify that this is what's happening with some logs in MeleeWeapon.HitCollider, then you should be able to work out how to get the character's root Health component from the sword's collider (which is what I did in the code snippet two posts up).
 
Yes, I had implemented what you had suggested and did not get any different results. The videos I posted included your code and the layers changing caused issues in the characters control. I don't know anything about coding and am just using this asset at face value and letting you know in-case you were unaware that this is how the system is currently working.

I'm not sure why your project it seems you are suggesting it is working and mine it does not but I guess I just need to take your word for it. I may try the collider log thing soon when I have time but i honestly don't even know what you're talking about and since I am just using the demo in a fresh project the results should be the same as yours. Also I can not code for the life of me, so if it's going to take some rebuilding core scripts to get those results I think I am best sticking to what I have since if I change things I will have problems when I update the TPC asset.

If this is all how you are intending for it to work than I don't want to waste anymore of anyone's time. I am not sure we are quite regestering the same thing. I think in the end I just want the shield only active while blocking was active (I think.. I think this where I got too after all this), seems more complicated than that though and maybe set up the other way around. Seemed worth bringing to attention some things that seemed odd in it's functionality out of the box ?

Thank you for your time though!
 
No worries, it definitely should be working in the demo scene for you the same way, unless you've changed anything about it like models or the character. Feel free to come back if you still can't work it out!
 
Top