FishNet icon indicating copy to clipboard operation
FishNet copied to clipboard

Loading scenes in pairs makes sync collections empty

Open Kromsalovo opened this issue 1 year ago • 2 comments

General Unity version: 2022.3.21f1 Fish-Networking version: 4.2.0

Description if you load scenes in pairs where 1 scene is persistent and never changes, it empties sync collections in this scene

string[] scenesToLoad = new string[] { "MultiplayerStuff", LevelName }; 
// i never change "MultiplayerStuff" as i have persistent data here, only swapping LevelName 
SceneLoadData sld = new SceneLoadData(scenesToLoad);
sld.ReplaceScenes = ReplaceOption.All;
sld.PreferredActiveScene = new PreferredScene(SceneLookupData.CreateData(LevelName));
SceneManager.LoadGlobalScenes(sld);

if i unload scenes manually without touching persistent one , this problem is not appearing

Replication Steps to reproduce the behavior:

  1. Import example package
  2. Load Sample Scene
  3. Press play in the Unity editor and click Server and Client
  4. Press Space 3 times and on 3rd time collection that is inside Bug script on Test GameObject would be lost

Example File Bug.zip

Kromsalovo avatar Apr 17 '24 14:04 Kromsalovo

I'm not sure if I'd qualify this as a bug because it seems like it's unloading all scenes then reloading them. Which ironically is what most people want when you try to single load the same scene, but iirc FishNet rather just keeps the scene loaded.

I'll have to take a look at the code again and see what's making it unload the 'MultiplayerStuff' scene, then apply that to if only a single scene.

So in reality, it might actually be working exactly as it's supposed to. But the single scene load not refreshing is the actual bug.

Still labeling as bug though so I can get the single scene one working the same way. You should be able to also load the scene while disabling auto unload and it won't reload.

Edit: I see planned public bool ReloadScenes; inside SceneLoadData.Options. It shouldn't be reloading in any scenario unless that's set to true. So definitely could be undesired behavior after all.

FirstGearGames avatar Apr 22 '24 22:04 FirstGearGames

i agree that everything in current code suggests that unloadall->loadall is expected behaviour and if you want something to stay you should control it yourself, there also certaint differences between those 2 methods like when you get additional scenepresence changes with manual approach or problems happening with some scenes not unloading properly in build, so its for you to decide if you want to enforce this more clean unloadall-loadall way or add additional functionality to make my way possible(even if it introduces several differences in a way some callbacks gets called and possible bugs)

Kromsalovo avatar Apr 24 '24 05:04 Kromsalovo