-
Notifications
You must be signed in to change notification settings - Fork 437
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
NetworkObject
CheckObjectVisibility
doesn't work on client connection
#3185
Comments
Hi @babaq, I put together an example project to see if I could replicate the first issue you are having using ObjectSpawning.zip I then connect a client to replicate the late joining client issue described. I then spawned one more NetworkObject with the I then hit the (2) key to show the hidden I then connected a 2nd client to verify that even though the host and the connected client have visibility to the 3 spawned I then was able to show the Could you look at the project I have provided you and see if you can determine something that you might be doing differently? |
Hi @NoelStephensUnity I tested again and the problems disappeared, maybe because i have upgraded to Netcode v2.2. As the same result you show,
this make object invisible not only at the initial spawning, but also when late-joining client connects. I guess when new client join, the server will spawn the object, hence also initial spawning at client side. So the Doc need to update, current description is kind of confusing. Later when needed, the object can be visible using Then, i also test the second approach,
this have achieved the same result, as the Doc description. However, later |
This is expected behavior.
|
Here is my understanding and small rephrasing:
Only |
As a side note, I wrote some helper functions for manipulating network visibility which i wish Netcode could have provide them at the beginning, so i list them here just for your consideration. public static class NetVisExt
{
public static List<ulong> Observers(this NetworkObject no)
{
List<ulong> list = new();
var obs = no.GetObservers();
while (obs.MoveNext()) { list.Add(obs.Current); }
return list;
}
public static bool IsNetworkHideFromAll(this NetworkObject no)
{
int count = 0;
var obs = no.GetObservers();
while (obs.MoveNext()) { count++; }
return count == 0;
}
public static bool IsNetworkShowToAll(this NetworkObject no)
{
var nm = NetworkManager.Singleton;
if (nm != null && nm.IsServer)
{
int count = 0;
var obs = no.GetObservers();
while (obs.MoveNext()) { count++; }
return count == nm.ConnectedClientsIds.Count;
}
return false;
}
public static void NetworkShowHideOnly(this NetworkObject no, ulong clientid, bool isshow)
{
if (isshow) { NetworkShowOnlyTo(no, clientid); } else { NetworkHideOnlyFrom(no, clientid); }
}
public static void NetworkShowHideAll(this NetworkObject no, bool isshow)
{
if (isshow) { NetworkShowToAll(no); } else { NetworkHideFromAll(no); }
}
public static void NetworkShowOnlyTo(this NetworkObject no, ulong clientid)
{
var nm = NetworkManager.Singleton;
if (nm != null && nm.IsServer)
{
var ss = no.Observers();
var hs = nm.ConnectedClientsIds.Except(ss).ToArray();
if (hs.Contains(clientid)) { no.NetworkShow(clientid); }
foreach (var c in ss) { if (c != clientid) { no.NetworkHide(c); } }
}
}
public static void NetworkShowToAll(this NetworkObject no)
{
var nm = NetworkManager.Singleton;
if (nm != null && nm.IsServer)
{
foreach (var c in nm.ConnectedClientsIds.Except(no.Observers()))
{
no.NetworkShow(c);
}
}
}
public static void NetworkHideOnlyFrom(this NetworkObject no, ulong clientid)
{
var nm = NetworkManager.Singleton;
if (nm != null && nm.IsServer)
{
var ss = no.Observers();
var hs = nm.ConnectedClientsIds.Except(ss).ToArray();
if (ss.Contains(clientid)) { no.NetworkHide(clientid); }
foreach (var c in hs) { if (c != clientid) { no.NetworkShow(c); } }
}
}
public static void NetworkHideFromAll(this NetworkObject no)
{
var nm = NetworkManager.Singleton;
if (nm != null && nm.IsServer)
{
foreach (var c in no.Observers())
{
no.NetworkHide(c);
}
}
}
} |
@babaq
Then the rest where you are doing status checks I would need to think about as the context changes between which network topology is being used...but they are all worth contemplating. |
Description
I want to spawn a networkprefab without any client visibility, first i tried to set no observers before spawn:
this results a spawned object with zero observers, but when a late-join client connects, the object gets spawned on client. The documentation says this is the intended normal behavior, because it only works at the initial spawning.
Then, the documentation says the
CheckObjectVisibility
will work at both initial spawning and new client connection, so i tried this:it did spawn with no observers as the previous approach, but when late-join client connects, it still spawn the object on client.
Reproduce Steps
NetworkObject.CheckObjectVisibility += _ => false;
Actual Outcome
a spawned object with visibility always set to false still spawns on late-join client
Expected Outcome
a spawned object with visibility always set to false should be invisible to all connected client and future late-join clients
Environment
The text was updated successfully, but these errors were encountered: