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

IsOwner is False on owning Client when spawning object during ConnectionApproval.

未关闭
#3,802 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stat:awaiting-response stat:imported type:bug
主要语言
C#
星标
2.3k
派生
461
平均合并
3 天 16 小时
30 天内合并 PR
20

描述

Description

When spawning a Player object and a Player Owned object during Connection Approval, the Network Behaviors on the Clients GameObjects report IsOwner as being false, while the Network Object reports IsOwner as true.

It seems based on my repro project that the client receives the CreateObjectMessages for their Player and Owned object before their ConnectionApproved message. This causes the client to not have an assigned clientId so when the Network Behaviours initialze, they set IsOwner as false (Although, the Network Object seems to include IsOwner as part of its serialized data). My guess is that this is some kind of knock on from distributed authority being added to the library (I am 99% certain I have done what is happening in this repro here in other projects from a couple years ago...)

I think that the fix here (at least if I was to rework my code) would be to do all spawning once the connection is approved and once the client reports they are ready to get their objects (somehow)

I have included a small repro project with this report.

Reproduce Steps

Download the repro project.
ownership_issue_repro.zip

  1. Go to Scenes and open Bootstrap
  2. Click the MPPM dropdown near the play button and select "Client - Direct Connection"
  3. Click Play, and wait for the client to connect to the host.
  4. Find their Player(clone) or ClientObject(clone) object in the hierarchy, note that IsOwner is True on the Network Object.
  5. Switch inspector to Debug mode, and look at the IsOwner field on the attached network behaviors. Note that it is set to false.
  6. Additionally, note that some random network objects are in the hierarchy, which were never spawned.
Actual Outcome

Objects spawned during ConnectionApproval are incorrectly set as IsOwner = false;

Expected Outcome

Either an error / warning is called when spawning with ownership for a none approved client OR the spawn messages are only sent once the approval is complete and the client has their clientId

Environment
  • OS: Windows 11
  • Unity Version: 6000.0.60f1
  • Netcode Version: 2.7.0
  • Netcode Topology: Client-Server

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从随附的 ownership_issue_repro.zip 开始,使用 Client - Direct Connection 设置通过 Bootstrap scene 重现该问题。跟踪 ConnectionApproval、CreateObjectMessages、clientId 分配以及 Network Behavior 初始化;完成的标准是,在审批期间生成的对象报告一致的所有权,且不会出现未生成的对象。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, unity
领域
networking
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。