Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpc and NetworkVariable won't work after PlayerPrefab respawned #3059

Open
Claude-Leo opened this issue Sep 11, 2024 · 3 comments
Open

Rpc and NetworkVariable won't work after PlayerPrefab respawned #3059

Claude-Leo opened this issue Sep 11, 2024 · 3 comments
Assignees
Labels
priority:medium stat:imported Issue is tracked internally at Unity type:bug Bug Report

Comments

@Claude-Leo
Copy link

Description

When the client’s Player is destroyed it’s also removing the client as an observer on other network objects.
Here is a simple test scene

Environment

  • OS: Windows 10 Version 22H2
  • Unity Version: 6000.0.17f1
  • Netcode Version: 2.0.0-pre.4

Additional Context

This happens in version 2.0.0-pre.4, 1.11 has no such issue.
Cerestorm and I found this bug.

@Claude-Leo Claude-Leo added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Sep 11, 2024
@fluong6 fluong6 assigned fluong6 and samlucas-unity and unassigned fluong6 Sep 16, 2024
@samlucas-unity
Copy link
Contributor

samlucas-unity commented Sep 24, 2024

I'm not seeing the issue on either 2.0.0-pre.4 or latest NGO. When running the sample (I retrieved it from, the discussions thread) I see the client continually destroy and recreate itself and I see the RPC being sent for both clients. Given your description of your issue I was expecting after the respawn the client would no longer receive its RPCs. I've closed out the issue but if you can still reproduce it please re-open it with any more reproduction steps you have and I will take another look.

@ezoray
Copy link

ezoray commented Sep 30, 2024

Hi @samlucas-unity, it was me who replied to that thread (cerestorm) and I guess I wasn't clear enough to the OP.

The issue is if the client Player object is Destroyed by the host (as opposed to being Despawned) the client is removed as an observer from any other network objects. NGO 1.11 copes with this with the client still observing but the references to the client under Observers goes blank in the Unity editor, which makes sense as they're a reference to the client's Player object.
In NGO 2.0.0 the client is removed under the Observers list for any network object it was observing at the time the client Player was destroyed.

I've attached the code I used to test this if it helps.
lostobserver.unitypackage.zip

@samlucas-unity
Copy link
Contributor

Thanks for the reply, that really helped me get a solid repro of this issue. It is a regression from 1.11 and we have identified the code and I have a fix ready I'm just getting some tests around this to catch it in the future. For now you can remove this code:

// DANGO-TODO: When we fix the issue with observers not being applied to NetworkObjects,
// (client connect/disconnect) we can remove this hacky way of doing this.
// Basically, when a player disconnects and/or is destroyed they are removed as an observer from all other client
// NetworkOject instances.
if (networkObject.IsPlayerObject && !networkObject.IsOwner && networkObject.OwnerClientId != NetworkManager.LocalClientId)
{
    foreach (var netObject in SpawnedObjects)
    {
        if (netObject.Value.Observers.Contains(networkObject.OwnerClientId))
        {
            netObject.Value.Observers.Remove(networkObject.OwnerClientId);
        }
    }
}

In NetworkSpawnManager.cs.

I've reopened this issue and will close it again once I land the PR.

Thanks,

Sam

@samlucas-unity samlucas-unity reopened this Oct 4, 2024
@fluong6 fluong6 added priority:medium stat:imported Issue is tracked internally at Unity and removed stat:awaiting triage Status - Awaiting triage from the Netcode team. labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:medium stat:imported Issue is tracked internally at Unity type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

4 participants