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

Add Support for Nested NetworkObjects in Prefabs

未關閉
#2,637 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type:feature
主要語言
C#
星號
2.3k
分支
461
平均合併
3 天 16 小時
30 天內合併 PR
20

描述

Is your feature request related to a problem? Please describe.
One major pain point of using Unity Netcode for GameObjects (as well as many other networking solutions) is the lack of support for spawning nested NetworkObjects. Currently, if you try to spawn a prefab with nested NetworkObjects, the primary NetworkObject will be networked, while all the child NetworkObjects will not.

As an example, imagine that you are trying to spawn a boat with cannons that each player can move and shoot. In this scenario, it would make sense that (1) cannons should be parented to the boat and (2) any player should be able to take ownership of a cannon (separate of the boat) when they go to move/shoot it. This means that both the boat and the cannons would need to be NetworkObjects. However, because of this limitation, you would not be able to make one boat prefab with the cannons on it.

Describe the solution you'd like
Ideally, when a prefab with nested NetworkObjects is spawned, it should automatically network any child network objects.

Describe alternatives you've considered
You can work around the issues with nested NetworkObjects, but it requires designing your prefabs/scripts in less intuitive ways.

For instance, in the boat example I mentioned earlier, you could create cannon spawners that spawn the cannons separately when the boat is spawned. However, this has its own issues. Primarily:

  1. It is harder to position the cannons.
    • If you just try to position the cannons with the transform of the spawner, it will be difficult to visualize the final product.
    • Positioning the cannon prefab first and then replacing it with the spawner requires more work than necessary. Also, what if the boat model changes and you need to reposition the cannons? You'll have to add back in the cannon prefab, position it, move the spawner to that position, and delete the cannon prefab.
  2. In Editor, scripts on the boat cannot reference scripts on the cannons (and vice versa).
    • This means you may have to wire up scripts at runtime.
    • This also means that your code will have to check to make sure that the cannons have been spawned in before doing anything with them, since they aren't necessarily spawned at the same time as the boat.

There are other solutions to these types of problems, but they are generally more difficult to implement and/or encourage poor design.

Additional context
N/A

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

未指定檔案或測試。首先追蹤 prefabs 和 NetworkObjects 是如何生成的,然後確定巢狀子物件應如何註冊和擁有;完成的標準是,生成一個 prefab 會自動將其巢狀的 NetworkObjects 加入網路,同時保留父子關係和獨立的所有權。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp
領域
game-dev, networking
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。