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

Add Support for Nested NetworkObjects in Prefabs

Đang mở
#2,637 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

type:feature
Ngôn ngữ chính
C#
Star
2.3k
Fork
461
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
20

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Không có tệp hoặc bài kiểm thử nào được nêu tên. Hãy bắt đầu bằng cách theo dõi cách prefabs và NetworkObjects được spawn, sau đó xác định cách các đối tượng con lồng nhau sẽ được đăng ký và sở hữu; hoàn tất khi việc spawn một prefab tự động đưa các NetworkObjects lồng nhau của nó vào mạng, đồng thời giữ nguyên quan hệ parenting và quyền sở hữu riêng biệt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
game-dev, networking
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.