Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.1k stars 430 forks source link

Preload Network Prefab Addressables #2818

Open ayaazki opened 4 months ago

ayaazki commented 4 months ago

Description

I am trying to Preload Network prefabs from addressables without spawning, the sequence of the process is that I run the server, invoke preload, then run the client.

The issue is that the client connection is denied immediately. It only happens if the server invokes a preload for more than 17 prefabs, then:

It works only in two cases:

  1. If the loaded prefabs count is 17 or less, then the client late joining or reconnecting is not an issue.
  2. If the loaded prefabs count is more than 17, then it works only if the client is connected when the server invokes preloading Rpc.

Reproduce Steps

Iam testing on the (Dynamic prefab sample) project. https://docs-multiplayer.unity3d.com/netcode/current/learn/bitesize/bitesize-dynamicPrefabs/

  1. Open scene (05_API Playground Showcasing All Post-Connection Use-Cases).
  2. Create and Add some prefabs to the addressables .
  3. Add the prefabs to the Dynamic Prefabs References List in AppController class (The list items should be more than 17).
  4. Build addressables.
  5. Run As a Host.
  6. Click (Load All Prefabs Async)
  7. Now Run the client.

Actual Outcome

The client connection is denied, the disconnects.

Expected Outcome

The client connects and preload all prefabs that the server has loaded.

Environment

NoelStephensUnity commented 4 months ago

Still investigating,

Ufabsther commented 2 months ago

I can reproduce the bug with 16 prefabs but different conditions :

Also to note, the following log is coming from the client :

Started to load addressable with GUID: 05ea0814e604c4acf8ae3b7e0a5dfb07
Loaded prefab has been assigned to NetworkManager's PlayerPrefab
StartClient
ConnectionManager: Changed connection state from OfflineState to ClientConnectingState.
[Netcode] NetworkPrefab cannot be null (NetworkPrefab at index: -1)
[Netcode] Removing invalid prefabs from Network Prefab registration: {SourceHash: 0, TargetHash: 0}
ConnectionManager: Changed connection state from ClientConnectingState to OfflineState.
Disconnect

The connection approval workflow from ConnectionApprovalCallback is only run at Host startup, but doesn't get executed when a new client connects.

NoelStephensUnity commented 2 months ago

@Ufabsther Can you reproduce this using v1.9.1?

Ufabsther commented 2 months ago

Yes, it does reproduce with the last release 1.9.1 as well .

Ufabsther commented 1 month ago

After further investigation on the Netcode for GameObject 1.9.1 and , using parallel sync, I was able to determine the issue was just related to an oversized Disconnection Reason. [Netcode] Disconnect reason didn't fit. Disconnected without sending a reason. Consider shortening the reason string.

Thus there is nothing to fix on the SDK BUT we should either put a disclaimer on the Sample, or present a more practical exemple of this feature without using DisconnectionReason.

unnanego commented 22 hours ago

I am getting the same error when trying to preload prefabs before starting the server. After calling LoadAssetAsync and assigning the loaded GameObject to the NetworkPrefabs list I'm getting the NetworkPrefab cannot be null, even though it's definitely working fine later when I instantiate it.

Netcode 1.9.1