Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects
Automatically invoke `NetworkVariable.OnValueChanged` when spawning
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- C#
- Estrelas
- 2.3k
- Forks
- 461
- Merge médio
- 3d 16h
- PRs com merge (30d)
- 20
Descrição
Feedback
When load scene with in-scene placed NetworkObject or dynamically spawn NetworkObject, connected client would spawn the object and NetworkVariable value synced with the server. But the OnValueChanged is not called, even if the value has been synced with the value of server, and is different from the default value that has been set in NetworkBehaviour. The current behavior of skipping OnValueChanged when spawning also doesn't depend on where the OnValueChanged has been registered, in OnNetworkSpawn , OnNetworkPreSpawn or even in Awake.
This caused a lot of problems, because NetworkVariable may be a bool that enable/disable a renderer, or set a shader field through OnValueChanged. Skipping OnValueChanged would make render frame inconsistent with what's intended. This is specially annoying when late-join client starts to spawn all NetworkObject, without OnValueChanged the game states would drastically different from server. The problem also shows up when a previously NetworkHide object become visible again and client respwan the object but with inconsistent states from server.
Suggested Changes
When spawning, all NetworkVariable should be synchronized, and corresponding OnValueChanged should all get called, because clients are supposed to keep the same states as server. The server has likely changed the value of NetworkVariable and have already called the OnValueChanged on server side, so when spawning happens, client need to not only sync all values of NetworkVariable, but also call all OnValueChanged to keep the same states as server.
An intuitive way is to register OnValueChanged in OnNetworkPreSpawn, so that during subsequent spawning any valid callbacks registered will get called.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece rastreando a sincronização de NetworkVariable durante o spawn de NetworkObject, incluindo o registro de callbacks em Awake, OnNetworkPreSpawn e OnNetworkSpawn. Reproduza os casos descritos de objetos presentes na cena, gerados dinamicamente, de entrada tardia e de visibilidade com NetworkHide; considera-se concluído quando os valores sincronizados invocam OnValueChanged e o estado do cliente corresponde ao do servidor.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- csharp, unity
- Domínio
- game-dev, networking
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100