FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.39k stars 150 forks source link

Error after the server starts as a client if other clients have already joined #688

Closed maxkratt closed 5 months ago

maxkratt commented 5 months ago

General Unity version: 2022.3.16f1 Fish-Networking version: 4.3.4 Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1247489641884422224

Description If you start a server and then have two or more clients join it and then the server instance also starts as a client, the following error shows up on the server:

Object PlayerObject(Clone) and PlayerObject(Clone) in scene SceneIdBug have the same sceneId of 0. This will result in spawning errors. Exit play mode and use the Fish-Networking menu to rebuild sceneIds for scene SceneIdBug.
UnityEngine.Debug:LogError (object)
FishNet.Managing.Logging.LevelLoggingConfiguration:LogError (string) (at Assets/FishNet/Runtime/Managing/Logging/LevelLoggingConfiguration.cs:129)
FishNet.Managing.NetworkManager:InternalLogError (string) (at Assets/FishNet/Runtime/Managing/NetworkManager.Logging.cs:83)
FishNet.Utility.Extension.Scenes:<GetSceneNetworkObjects>g__TryDisplayDuplicateError|0_0 (FishNet.Object.NetworkObject,FishNet.Utility.Extension.Scenes/<>c__DisplayClass0_0&) (at Assets/FishNet/Runtime/Utility/Extension/Scenes.cs:80)
FishNet.Utility.Extension.Scenes:GetSceneNetworkObjects (UnityEngine.SceneManagement.Scene,bool,bool,bool,System.Collections.Generic.List`1<FishNet.Object.NetworkObject>&) (at Assets/FishNet/Runtime/Utility/Extension/Scenes.cs:61)
FishNet.Managing.Client.ClientObjects:RegisterAndDespawnSceneObjects (UnityEngine.SceneManagement.Scene) (at Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs:266)
FishNet.Managing.Client.ClientObjects:RegisterAndDespawnSceneObjects () (at Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs:256)
FishNet.Managing.Client.ClientManager:ParseAuthenticated (FishNet.Serializing.PooledReader) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:636)
FishNet.Managing.Client.ClientManager:ParseReader (FishNet.Serializing.PooledReader,FishNet.Transporting.Channel,bool) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:505)
FishNet.Managing.Client.ClientManager:ParseReceived (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:384)
FishNet.Managing.Client.ClientManager:Transport_OnClientReceivedData (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:342)
FishNet.Transporting.Tugboat.Tugboat:HandleClientReceivedDataArgs (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:238)
FishNet.Transporting.Tugboat.Client.ClientSocket:IterateIncoming () (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Core/ClientSocket.cs:295)
FishNet.Transporting.Tugboat.Tugboat:IterateIncoming (bool) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:211)
FishNet.Managing.Transporting.TransportManager:IterateIncoming (bool) (at Assets/FishNet/Runtime/Managing/Transporting/TransportManager.cs:705)
FishNet.Managing.Timing.TimeManager:TryIterateData (bool) (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:1017)
FishNet.Managing.Timing.TimeManager:IncreaseTick () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:670)
FishNet.Managing.Timing.TimeManager:<TickUpdate>g__MethodLogic|98_0 () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:342)
FishNet.Managing.Timing.TimeManager:TickUpdate () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:332)
FishNet.Transporting.NetworkReaderLoop:Update () (at Assets/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)

Replication Steps to reproduce the behavior:

  1. Import example package
  2. Build the game and run two instances of the build
  3. Press play in the editor and start as a server
  4. Start the two builds as clients
  5. Start the editor as a client
  6. See error

Expected behavior No error is expected, it doesn't occur in older versions.

Example Package SceneIdBug.zip

FirstGearGames commented 5 months ago

That shouldn't be possible. SceneId 0 indicates not a scene object, thus it should not be initialized as one.

From the context of this I'm assuming this is on a player object?

This could be a regression where when players are spawned in right as scenes are loaded FishNet thinks they're scene objects.

On Tue, Jun 4, 2024, 7:28 AM Max Kratt @.***> wrote:

General Unity version: 2022.3.16f1 Fish-Networking version: 4.3.4 Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1247489641884422224

Description If you start a server and then have two or more clients join it and then the server instance also starts as a client, the following error shows up on the server:

Object PlayerObject(Clone) and PlayerObject(Clone) in scene SceneIdBug have the same sceneId of 0. This will result in spawning errors. Exit play mode and use the Fish-Networking menu to rebuild sceneIds for scene SceneIdBug. UnityEngine.Debug:LogError (object) FishNet.Managing.Logging.LevelLoggingConfiguration:LogError (string) (at Assets/FishNet/Runtime/Managing/Logging/LevelLoggingConfiguration.cs:129) FishNet.Managing.NetworkManager:InternalLogError (string) (at Assets/FishNet/Runtime/Managing/NetworkManager.Logging.cs:83) FishNet.Utility.Extension.Scenes:g__TryDisplayDuplicateError|0_0 (FishNet.Object.NetworkObject,FishNet.Utility.Extension.Scenes/<>cDisplayClass0_0&) (at Assets/FishNet/Runtime/Utility/Extension/Scenes.cs:80) FishNet.Utility.Extension.Scenes:GetSceneNetworkObjects (UnityEngine.SceneManagement.Scene,bool,bool,bool,System.Collections.Generic.List`1&) (at Assets/FishNet/Runtime/Utility/Extension/Scenes.cs:61) FishNet.Managing.Client.ClientObjects:RegisterAndDespawnSceneObjects (UnityEngine.SceneManagement.Scene) (at Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs:266) FishNet.Managing.Client.ClientObjects:RegisterAndDespawnSceneObjects () (at Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs:256) FishNet.Managing.Client.ClientManager:ParseAuthenticated (FishNet.Serializing.PooledReader) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:636) FishNet.Managing.Client.ClientManager:ParseReader (FishNet.Serializing.PooledReader,FishNet.Transporting.Channel,bool) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:505) FishNet.Managing.Client.ClientManager:ParseReceived (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:384) FishNet.Managing.Client.ClientManager:Transport_OnClientReceivedData (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:342) FishNet.Transporting.Tugboat.Tugboat:HandleClientReceivedDataArgs (FishNet.Transporting.ClientReceivedDataArgs) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:238) FishNet.Transporting.Tugboat.Client.ClientSocket:IterateIncoming () (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Core/ClientSocket.cs:295) FishNet.Transporting.Tugboat.Tugboat:IterateIncoming (bool) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:211) FishNet.Managing.Transporting.TransportManager:IterateIncoming (bool) (at Assets/FishNet/Runtime/Managing/Transporting/TransportManager.cs:705) FishNet.Managing.Timing.TimeManager:TryIterateData (bool) (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:1017) FishNet.Managing.Timing.TimeManager:IncreaseTick () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:670) FishNet.Managing.Timing.TimeManager:gMethodLogic|98_0 () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:342) FishNet.Managing.Timing.TimeManager:TickUpdate () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:332) FishNet.Transporting.NetworkReaderLoop:Update () (at Assets/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)

Replication Steps to reproduce the behavior:

  1. Import example package
  2. Build the game and run two instances of the build
  3. Press play in the editor and start as a server
  4. Start the two builds as clients
  5. Start the editor as a client
  6. See error

Expected behavior No error is expected, it doesn't occur in older versions.

Example Package SceneIdBug.zip https://github.com/user-attachments/files/15550626/SceneIdBug.zip

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3XVLSB2HP2A4MS5VJTZFWQHFAVCNFSM6AAAAABIYKBJ4GVHI2DSMVQWIX3LMV43ASLTON2WKOZSGMZTGMRXHEZTENA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

maxkratt commented 5 months ago

Yep, it's on the player object.

FirstGearGames commented 5 months ago

Okay thanks.

On Tue, Jun 4, 2024, 7:35 AM Max Kratt @.***> wrote:

Yep, it's on the player object.

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/688#issuecomment-2147308264, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3TVKF7OQRVXCK5HSQLZFWRAJAVCNFSM6AAAAABIYKBJ4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBXGMYDQMRWGQ . You are receiving this because you commented.Message ID: @.***>

FirstGearGames commented 5 months ago

If you or anyone is around can you please try something for me, I'm currently burdened with other tasks.

Find this method public static void GetSceneNetworkObjects(Scene s, bool firstOnly, bool errorOnDuplicates, bool ignoreUnsetSceneIds, ref List<NetworkObject> result)

and replace

if (!ignoreUnsetSceneIds && !nob.IsSceneObject)
if (!ignoreUnsetSceneIds && !item.IsSceneObject)

with...

//flip ignoreUnsetSceneIds check.
if (ignoreUnsetSceneIds && !nob.IsSceneObject)
if (ignoreUnsetSceneIds && !item.IsSceneObject)
maxkratt commented 5 months ago

If you or anyone is around can you please try something for me, I'm currently burdened with other tasks.

Find this method public static void GetSceneNetworkObjects(Scene s, bool firstOnly, bool errorOnDuplicates, bool ignoreUnsetSceneIds, ref List<NetworkObject> result)

and replace

if (!ignoreUnsetSceneIds && !nob.IsSceneObject)
if (!ignoreUnsetSceneIds && !item.IsSceneObject)

with...

//flip ignoreUnsetSceneIds check.
if (ignoreUnsetSceneIds && !nob.IsSceneObject)
if (ignoreUnsetSceneIds && !item.IsSceneObject)

Those changes seemed to resolve the error 👍

FirstGearGames commented 5 months ago

Thank you!

On Tue, Jun 4, 2024, 12:42 PM Max Kratt @.***> wrote:

If you or anyone is around can you please try something for me, I'm currently burdened with other tasks.

Find this method public static void GetSceneNetworkObjects(Scene s, bool firstOnly, bool errorOnDuplicates, bool ignoreUnsetSceneIds, ref List result)

and replace

if (!ignoreUnsetSceneIds && !nob.IsSceneObject)if (!ignoreUnsetSceneIds && !item.IsSceneObject)

with...

//flip ignoreUnsetSceneIds check.if (ignoreUnsetSceneIds && !nob.IsSceneObject)if (ignoreUnsetSceneIds && !item.IsSceneObject)

Those changes seemed to resolve the error 👍

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/688#issuecomment-2147972132, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3Q7NMAFDZQDQLH2JLTZFXU6FAVCNFSM6AAAAABIYKBJ4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBXHE3TEMJTGI . You are receiving this because you commented.Message ID: @.***>

FirstGearGames commented 5 months ago

Resolved pending release today 4.3.5

Polarhigh commented 5 months ago

Hi! I noticed that these changes are not on the github, they are only in the unitypackage on the release page @FirstGearGames