Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects
NetworkShow and CheckObjectVisibility limiting visibiliy management flexibility (and does not work as intened in documentation)
@NoelStephensUnity 已经在做这个了。
开始于 2023年10月5日。
- 主要语言
- C#
- 星标
- 2.3k
- 派生
- 461
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 20
描述
Is your feature request related to a problem? Please describe.
Using a NetworkShow and CheckObjectVisibility is known to be impossible, and there were already some discussions about it in the past (see https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2546 and https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2609 )
A resolution of the above issues was an introduction of SpawnWithObservers property on NetworkObject. That indeed solved situations where it was necessary to spawn object with no observers. However, in my case, I want to spawn a player object with owner-only visibility, and later add additional objects. However if I do it with:
go.GetComponent<NetworkObject>().CheckObjectVisibility = ((cId) =>
{
return cId == go.GetComponent<NetworkObject>().OwnerClientId;
});
It results in fully blocking me from any further network visibility management with NetworkShow / NetworkHide.
Interesting that the documentation tells that the above approach is actually valid:
https://docs-multiplayer.unity3d.com/netcode/current/basics/object-visibility/
It's said that CheckObjectVisibility is checked only at object spawn, and it's advised to use NetworkShow/NetworkHide after that. However currently it's not how it works, and it's necessary to both update the delegate method and do NetworkShow every time I need to show some object to some client. I feel there is a redundancy in updating a delegate in addition to NetworkShow.
Describe the solution you'd like
- Currently, in my local branch of NGO I just commented out a visibility check in
NetworkShowthat prevents the method from doing what is supposed to do. This is the fastest solution. - More beautiful solution would be to have a new argument to spawn a function to setup initial observes of the object:
SpawnAsPlayerObject(clientId, observers: new List<ulong>{.....});
Spawn(observers: new List<ulong>{.....});
- Or as it was proposed previously in https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2546 some sort of new delegate such as
CheckObjectInitialVisibilitywould also fix the issue
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。