Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects

NetworkShow and CheckObjectVisibility limiting visibiliy management flexibility (and does not work as intened in documentation)

Aberta
#2,711 7 comentários 0 reações 1 responsável Ver no GitHub

@NoelStephensUnity já está trabalhando nisso.

Desde 5/10/2023.

stat:Investigating stat:reply-needed type:feature
Linguagem predominante
C#
Estrelas
2.3k
Forks
461
Merge médio
3d 16h
PRs com merge (30d)
20

Descrição

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 NetworkShow that 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>{.....});

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.