Add a single unified “OnNetworkStarted” event to NetworkManager
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- csharp, unity
- 領域
- api, networking
調査の方向性
NetworkManager、特に internal Initialize(bool server) から始め、既存の OnServerStarted と OnClientConnectedCallback のライフサイクルパスおよび関連するテストを調査します。完了条件は、サーバー、クライアント、ホストの各モードでネットワークスタックとトランスポートの準備が整った後に、単一のイベントが1回だけ発生することです。また、複数の NetworkManager インスタンスとエディターのリロードを対象とした動作もカバーします。
索引モデルが issue の本文から書いたものです。
説明
The problem
There’s no single event that fires once when networking starts, regardless of mode
Currently you need to handle both OnServerStarted and OnClientConnectedCallback, which leads to redundant or missing calls depending on the mode (client/server)
Using per-connection callbacks for this is unreliable, and managing timing around the singleton or validation properties(e.g IsListening) adds unnecessary complexity
Unless i am missing something, to me this dont feels right
Current workflow
The current workaround is using coroutines or polling to wait until the singleton exists and the NetworkManager is listening.
This adds overhead and makes initialization logic fragile, even more for singleplayer sessions where the code may keep waiting forever as no connections are made
Example (based on forums suggestions):
void OnEnable()
{
StartCoroutine(SubscribeToNetworkManagerEvents());
}
IEnumerator SubscribeToNetworkManagerEvents()
{
yield return new WaitUntil(() => NetworkManager.Singleton); //This is fragile, and may add other problems, and no mention to cancelations
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallback; //called on clients but unclear about standalone server
NetworkManager.Singleton.OnServerStarted += OnServerStarted; //never called on non host client
}
void OnDestroy()
{
if (NetworkManager.Singleton)
{
NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnectedCallback;
NetworkManager.Singleton.OnServerStarted -= OnServerStarted;
}
initialized = false;
}
void OnClientConnectedCallback(parameters)
{
RegisterMessageHandler();
}
void OnServerStarted(parameters)
{
RegisterMessageHandler();
}
bool initialized;
//Both on client connected callback and server started calls this other method
void RegisterMessageHandler()
{
if(initialized)
return;
//For example
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("a", B);
// In this case, Singleton can be null and CustomMessagingManager also can be null, thats why we need the yield
initialized = true;
}
These yields are required only because there is no dedicated lifecycle event indicating when the NetworkManager and its subsystems (like CustomMessagingManager) are fully initialized
As result, developers must manually simulate this missing initialization phase using coroutines or polling, which makes code more complex
Posible solution
Add new public static Action<NetworkManager> OnNetworkStarted event to NetworkManager
Triggered once when the network stack has been initialized and the transport is ready, regardless of whether it’s running as server, client, or host.
Passing the Network manager initialized (as after working on the last pull request, i saw on the tests part and other parts of code might exist more than one NetworkManager)
This would change the workflow to a much more convenient one like this
NetworkManager networkManager;
void OnEnable()
{
NetworkManager.OnNetworkStarted += OnNetworkStarted;
}
void OnNetworkStarted(NetworkManager networkManager)
{
this.networkManager = networkManager;
networkManager.CustomMessagingManager.RegisterNamedMessageHandler("a", B);
}
void OnDestroy()
{
if (networkManager)
networkManager.CustomMessagingManager.UnregisterNamedMessageHandler("a");
}
[!NOTE]
WhileNetworkBehaviour.OnNetworkSpawncan be used for components, this event would support use cases where no scene objects are involved (e.g ScriptableObjects or systems initialized outside scene contexts). It provides a clean, unified hook for all modes.This change would mostly take 2 lines
public static Action<NetworkManager> OnNetworkStartedon NetworkManager classOnNetworkStarter?.Invoke(This);at the very end of NetworkManager'sinternal void Initialize(bool server)methodIt only may cause problems on having it static with the editor reloading feature, but that could be arranged cleaning the event with the
[RuntimeInitializeOnLoadAttribute]
- 主要言語
- C#
- スター
- 2.3k
- フォーク
- 461
- 平均マージ
- 3日 16時間
- マージ済み PR(30日)
- 20
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Unity-Technologies/com.unity.netcode.gameobjects のほかの issue
-
stat:import type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
stat:reply-needed type:support
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
Unity-Technologies/com.unity.netcode.gameobjects#4095 · コメント 10 件 ·
-
stat:awaiting-triage stat:Investigating type:bug
Unity-Technologies/com.unity.netcode.gameobjects#3912 · コメント 5 件 · 担当者 1 名 ·
-
Tracking type:feature-2.x
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Unity-Technologies/com.unity.netcode.gameobjects#3870 · コメント 5 件 ·
-
Tracking type:feature
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
Unity-Technologies/com.unity.netcode.gameobjects#3830 · コメント 7 件 ·
Unity-Technologies/com.unity.netcode.gameobjects の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
azurenoops/spin_agent#975 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
dotnet/AspNetCore.Docs#37699 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SubtitleEdit/subtitleedit#15108 · コメント 1 件 ·