Character respawn and other issues (IK stops syncing)

CoffeeOD

New member
Assets and versions
Unity: 2019.2.12f1
UFPS: Ultimate FPS: 2.1.9
PUN Addon: current ver. 1.0.3

Problem 1) Master client cannot cause damage to joined players until death event is launched
Upon master spawning secondary client, master is unable to cause damage to client BUT client can cause damage to master. When master client dies (client kills him), problem goes away.

Problem 2) Respawn causes CharacterIK to be disabled on remote client.
This not always happens on first kill, but I have seen this both on fresh project and existing project. When remote character dies CharacterIK is disabled but never enabled again, this means moving head up/down is not working.

If I enable remote character CharacterIK component manually from inside Unity editor, everything starts working normally which means head up/down syncing for my client (who is inside Unity editor). This has happen both in editor and using only builds.

In this video, I kill character and take control of it (using another window), when I respawn, I try to move my head up and down, which as you can see, is not syncing.

Video:

I tried with very basic setup following opsive tutorials, with recent test I did was:
  1. Copy demo scene.,
  2. Copy demo scene character
  3. Use "Pun Character" tool within opsive addon editor (turn objects into PUN objects).
  4. Build and kill each other.
 
Thanks - I was able to reproduce the second one. I wasn't able to reproduce the first one though - are you able to reproduce it within the demo scene of a fresh project?

To fix the second problem open Health.cs and replace m_NetworkInfo.IsServer with m_NetworkInfo.IsLocalPlayer at the top of Health.Damage and Health.Die. You'll also want to change the following within Health.Damage:

Code:
                Die(position, force, attacker);
With:
Code:
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
                if (m_NetworkInfo == null || m_NetworkInfo.IsLocalPlayer()) {
#endif
                    Die(position, force, attacker);
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
                }
#endif
 
Thanks for the reply Justin, I will try that health.cs modification soon as possible.

About first problem. I did as follows:
  • Copy demo scene.,
  • Copy demo scene character
  • Use "Pun Character" tool within opsive addon editor (turn objects into PUN objects).
  • Build and kill each other.
Video:

Notice in the inspector, CharacterIK gets disabled but never enabled back.

I also send you email which had this topic link attached, including google drive link to the same project in case you want to check it out.
 
Last edited:
Very dirty quick "fix" was to add enabled = true; on the CharacterIK.cs OnRespawn function, this forced value to true. Seems have temporarily fixed the issue.

C#:
        private void OnRespawn()
        {
            enabled = m_Enable;
            m_ImmediatePosition = true;
        }
to
C#:
        private void OnRespawn()
        {
            enabled = m_Enable;
            enabled = true;
            m_ImmediatePosition = true;
        }

Honestly I have not looked into UFPS codebase that deep as of yet, but seems OnDeath() disables variable and sets m_Enable to false, then OnRespawn() set enable state according to m_Enable value. I can only assume that m_Enable never gets set again before calling OnRespawn(), in multiplayer at least.

I dont recommend anyone doing this, just playing around so I can continue working on the PUN part.
 
The post above fixes that error :) I wasn't able to reproduce the first one where the character doesn't get damaged. But the fix above might work for that as well.
 
Hey @CoffeeOD,
I faced the same Problem 1 in my game as well. What I figured was that somehow m_ActiveItem[0] is not getting set in the Inventory.cs
for Master Clients Remote Instance's.
May be it is caused because of LoadDefaultLayout not getting called on remote instance's of Master Client.
How I fixed it was that I am calling Inventory.LoadDefaultLayout() in the custom script that I had attached to my player prefab.
I know it is still a hack, but I guess it suffice for now.
@Justin any idea why LoadDefaultLayout() might fail on the the Master client's remote instance's.

Here is the script that I attached to player prefab.

public class LoadDefaultLoadout : MonoBehaviour
{
IEnumerator Start()
{
yield return new WaitForSeconds(2);
GetComponent<Inventory>().LoadDefaultLoadout();
}
}
 
You should not need to call LoadDefaultLoadout manually. This bug occurred more than a year ago and I haven't had any recent reports of it so I'm fairly confident that it fixed. Are you able to reproduce it within the demo scene of a fresh project?
 
Top