#stops syncing on the client that had their player removed
1 messages · Page 1 of 1 (latest)
What could be happening is that the player object is getting despawned before the RPC gets a change to run
the spectator camera gets spawned
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
MouseMovement would have been destroyed with the player. So you would need a separate script to move the spectator camera
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
Hit() is called by clients or the server?
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;
}
}
What script is controlling the spectator camera?
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.
So the player object isn't getting despawned on the clients?
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
yes. but its hard to tell what is what
Would say that this is probably not unrelated then
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
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
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
As I said, even if it seems to go through, you could still be interrupting things - as evidence by this
Sending an RPC and destroying the NetworkBehaviour that called that RPC all in the same frame I would say is a bad idea
well that was the purpose of testing with DestroyPlayerServerRpc
which had the same issues, i can check if it throws that error
Depending on how you set this up, this likely doesn't change the issue I'm describing, just adds a step to it
In any case. despawning the player will not cause the other network objects to stop syncing.
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
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
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
that would also require removing all components that I add in the future
seems like a lot of overhead and room for missing things
Why?
because I then have to add them back on respawn and stuff
well that wasn't my point it was keeping track of things to enable and disable seems redundant and fallible
either way I can send it
The same could be said for having to destroy the player object, spawn a spectator camera and respawn another player object later
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
private void TogglePlayerScripts(bool toggle)
{
foreach(var playerScript in playerScripts)
playerScript.enabled = toggle;
}
I would hardly say a couple lines of code adds overhead
It also avoids the entire situation you're in right now which is causing errors
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
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
I could remove observers as well which I think to be a better solution but Id rather be able to solve this