#stops syncing on the client that had their player removed

1 messages · Page 1 of 1 (latest)

eternal canopy
#

What could be happening is that the player object is getting despawned before the RPC gets a change to run

sacred sphinx
#

Ive also tried making the SpawnSpectator call DestroyPlayerServerRpc

#

could it be because there is a camera only on the client that now has null transforms?
spawned in MouseMovement

eternal canopy
#

MouseMovement would have been destroyed with the player. So you would need a separate script to move the spectator camera

sacred sphinx
#

I am saying mousemovement instantiates a camera that has a parent transform of a point on the player. the parent transform is removed when despawned but the camera remains as its only on the clientside

#

i am testing now

#

because everything is fine if the host dies as well

#

unsure if related but

#
[Netcode] [Deferred OnSpawn] Messages were received for a trigger of type NetworkTransformMessage associated with id (8), but the NetworkObject was not received within the timeout period 10 second(s).
UnityEngine.Debug:LogWarning (object)
Unity.Netcode.NetworkLog:LogWarning (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs:28)
Unity.Netcode.DeferredMessageManager:PurgeTrigger (Unity.Netcode.IDeferredNetworkMessageManager/TriggerType,ulong,Unity.Netcode.DeferredMessageManager/TriggerInfo) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs:117)
Unity.Netcode.DeferredMessageManager:CleanupStaleTriggers () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs:84)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:374)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkPostLateUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:286)
#

doesn't seem to be camera issue

#

video of issue

past cedar
#

Hit() is called by clients or the server?

sacred sphinx
#

server, only by the zombie script

public class Zombie : NetworkBehaviour
{
    public float speed = 100f;

    public float hitDistance = 100f;
    public int damage = 10;
    public float hitDelay = 1f;

    float lastHit = 0f;

    void Update()
    {
        if (!IsHost) return;

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        if (players.Length < 1)
        {
            return;
        }

        GameObject closest = players[0];
        float distanceClosest = float.MaxValue;

        foreach (GameObject player in players)
        {
            float distance = CalcDistance(player);
            if (distance < distanceClosest)
            {
                closest = player;
                distanceClosest = distance;
            }
        }

        Vector3 direction = CalcDirection(closest);
        direction.y = 0;

        transform.position += speed * Time.deltaTime * direction;

        TryHitPlayer(closest);
    }

    void TryHitPlayer(GameObject player)
    {
        CapsuleCollider zombieCollider = GetComponent<CapsuleCollider>();
        CapsuleCollider playerCollider = player.GetComponent<CapsuleCollider>();

        float fullHitDistance = hitDistance + zombieCollider.radius + playerCollider.radius;

        float distance = Vector3.Distance(transform.position, player.transform.position);

        if (distance <= fullHitDistance && Time.time - lastHit >= hitDelay)
        {
            lastHit = Time.time;
            PlayerHealth health = player.GetComponent<PlayerHealth>();
            health.Hit(damage);
        }
    }

    float CalcDistance(GameObject target)
    {
        return Vector3.Distance(transform.position, target.transform.position);
    }

    Vector3 CalcDirection(GameObject target)
    {
        return (target.transform.position - transform.position).normalized;
    }
}
eternal canopy
#

What script is controlling the spectator camera?

sacred sphinx
#

nothing its just there

#

it spawns at the hosts camera position for now because the part of the script that gets the position runs on the server side and gathers that position from the hosts camera.

eternal canopy
#

So the player object isn't getting despawned on the clients?

sacred sphinx
#

the player is getting removed but all existing objects no longer have their transforms synced

#

did you see the video?

#

weird points:

  • bullets are spawned and synced on the client
  • zombie doesn't die
  • player is removed
eternal canopy
#

yes. but its hard to tell what is what

past cedar
sacred sphinx
#

I don't get that error if i dont destroy the player

#

I believe

#

let me check

#

yeah

#

if the player doesn't die, no error

#

and if the player dies repeatedly without getting despawned, it spawns the spectator camera and everything syncs with no error still

past cedar
#
SpawnSpectatorClientRpc(cameraPosition, cameraRotation);
    // SceneManager.LoadScene("StartMenu", LoadSceneMode.Additive);

    NetworkObject networkObject = gameObject.GetComponent<NetworkObject>();
    networkObject.Despawn();
}

Have you tried a different set up than this? I would guess that this is probably not a safe way of doing things

#

even if the RPC seems to go through

sacred sphinx
#

thats not the version of code im running that was an artifact from testing

#

here is current

#

wrong one

#

ive tried despawning in a [ServerRpc] called by SpawnSpectator as well so they are ordered

#

spectator camera gets spawned though so its not a race I dont think

past cedar
#

Sending an RPC and destroying the NetworkBehaviour that called that RPC all in the same frame I would say is a bad idea

sacred sphinx
#

well that was the purpose of testing with DestroyPlayerServerRpc

#

which had the same issues, i can check if it throws that error

past cedar
sacred sphinx
#

why not?

#

client rpc -> server rpc -> destroy

#

must be ordered can not race

eternal canopy
#

In any case. despawning the player will not cause the other network objects to stop syncing.

sacred sphinx
#

if it causes a fatal error in the network stack it could

#
void Kill()
    {
        GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
        Vector3 cameraPosition = camera.transform.position;
        Quaternion cameraRotation = camera.transform.rotation;

        SpawnSpectatorClientRpc(cameraPosition, cameraRotation);
        // SceneManager.LoadScene("StartMenu", LoadSceneMode.Additive);
    }

    [ClientRpc]
    void SpawnSpectatorClientRpc(Vector3 position, Quaternion rotation)
    {
        if (!IsOwner) return;
        Destroy(GameObject.FindGameObjectWithTag("MainCamera"));
        Instantiate(spectatorPref, position, rotation);
        DestroyPlayerServerRpc();
    }

    [ServerRpc]
    void DestroyPlayerServerRpc()
    {
        NetworkObject networkObject = gameObject.GetComponent<NetworkObject>();
        networkObject.Despawn();
    }
#

testing with this

#

error is still thrown

past cedar
#

What happens if you remove the Destroy call in the ClientRpc

#

for MainCamera

sacred sphinx
#

same issue that was just testing if it was something weird with the camera only existing on the client side

#

i will test again regardless

#

for sanity

#

I appreciate the help btw

#

I can call if you think that would be helpful at any point

#

same error

past cedar
#

Odd. Hard to say what it could be without having the project in front of me

#

Regardless of the error, I would probably just pivot away from despawning the player object

#

and just hide the visuals of the player when it dies, to turn it in to an invisible spectator

sacred sphinx
#

that would also require removing all components that I add in the future

#

seems like a lot of overhead and room for missing things

sacred sphinx
#

because I then have to add them back on respawn and stuff

sacred sphinx
#

cant shoot move look around

past cedar
#

Just disable them

#

You shouldn't be removing components on NetworkObjects anyway

sacred sphinx
#

well that wasn't my point it was keeping track of things to enable and disable seems redundant and fallible

sacred sphinx
past cedar
sacred sphinx
#

But i have prefabs for those

#

just spawn player and spawn spectator

#

not enable/disable this list of components

#

without lib folder which i believe is fine

#

testing was done in the greybox scene

past cedar
#

It also avoids the entire situation you're in right now which is causing errors

sacred sphinx
#

and where is playerScripts from

#

this is just avoiding an issue that shouldn't be an issue

#

and may create other issues later on

#

is this related to destroying any owned object?

#

destroying an object parenting the clients camera?

#

Im sorry but I dont think it correct to just ignore and move on

#

that might be reasonable for this problem but what about others I will run into

#

I cant keep duct taping it together

past cedar
#

It's not duct tape, it's a perfectly reasonable alternative

I'm sure it's possible to get your way working, but I'm unable to find out how to do that over Discord messages - so I'm trying to provide alternative solutions

#

There's no one right way to do things

sacred sphinx