ImPHL1
ImPHL1

Reputation: 41

Can't reload currently active scene with Fish Networking in Unity?

I'm trying to reload the currently active scene so players can start the game from the beginning but nothing happens! I'm using the code in the documentation and it works ok on loading other scenes but as I said nothing happens when trying to load the scene that is currently active on server and all clients! Here is the code:

[ServerRpc(RequireOwnership = false)]
[Server]
public void ReloadScene()
{
    SceneLoadData sld = new SceneLoadData("MainScene");
    sld.MovedNetworkObjects = new NetworkObject[] { _players[0].NetworkObject };
    sld.ReplaceScenes = ReplaceOption.All;
    NetworkManager.SceneManager.LoadGlobalScenes(sld);
}

Upvotes: 1

Views: 1100

Answers (2)

I'd comment but not enough rep apparently. I'm the creator of FishNet and I wanted to say that Iman Shirali is correct. Sometime in the future there will be a reload option; I've no ETA yet though.

Upvotes: 1

ImPHL1
ImPHL1

Reputation: 41

Ok based on what the creator of FishNet said reloading current active scene is not yet possible in FishNet so the workaround is to Load and empty scene, then load the first scene again. and remember to run this code on server not clients!

public void ReloadScene()
{
    SceneLoadData sld = new SceneLoadData("EmptyScene");
    sld.ReplaceScenes = ReplaceOption.All;
    NetworkManager.SceneManager.LoadGlobalScenes(sld);

    sld = new SceneLoadData("MainScene");
    sld.ReplaceScenes = ReplaceOption.All;
    NetworkManager.SceneManager.LoadGlobalScenes(sld);
}

Upvotes: 0

Related Questions