#Restarting the game with ServerChangeScene loses references

33 messages · Page 1 of 1 (latest)

pulsar rivet
#

I have a DDOL UI Manager on each player, with a reference to every canvas. These references go missing when the game restarts with this method

[Command(requiresAuthority =false)]
private void CmdRestartGame()
{
    Debug.Log("Changing scene to game again");
    NetworkManager.singleton.ServerChangeScene("GameScene");
}

I can't make this a prefab with the canvases as children as it's DDOL, and it needs the NetworkIdentity as it has some networking code inside (though, the UI isn't networked)

Not really sure what to do with this, I could get all references on runtime but it seems like a pretty big hassle, especially if this will be the same with future scripts.

idle glen
idle glen
#

If so, just kick it out of DDOL in OnServerChangeScene and OnClientChangeScene by moving it to the SceneManager active scene. That will let it be destroyed by the scene reload, and the new one will have all the refs you have set up.

#

Punt players and other stuff out of DDOL too, except Network Manager. Let all that reload normally like it would at the start of a game. Clients will stay connected, and get fresh players, etc.

pulsar rivet
#

Have never heard about kicking stuff out of DDOL, interesting, going to look into it now

idle glen
pulsar rivet
#

Oh wow thanks, I was looking into normal removal of DDOL. Trying out now

pulsar rivet
#

It's removing (most of it?) from DDOL, but still giving the missing reference

#

After scene reload ^^

#

Before scene reload vv

idle glen
#

what's that FirstGearGame malware doing there? 😮

idle glen
pulsar rivet
idle glen
#

and the virtuals are both empty so you don't need base method calls

pulsar rivet
#

ah okay

pulsar rivet
idle glen
#

You're doing it in the wrong overrides - look carefully at the names I gave above

pulsar rivet
#

oh wow subtle difference

#

retrying

idle glen
#

subtle but important 🙂 These run before the scene reload, the others run after and wouldn't do you any good

pulsar rivet
#

it's not found for the client one, server is fine

#

no suitable method to override

idle glen
#

IDE needs to give you the correct signature

#

public virtual void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling) { }

pulsar rivet
#

retrying

pulsar rivet
#

I've figured it out!

#

Had a lot of issues as some logic was being called from the NetworkManager OnStart's, which wasn't being ran again