We are working on upgrading our large application from 2019 to 2022, and we help for for a long time because of the networking code switch over. Our project has been worked on by many different people, most who have moved on to different groups, so I’m trying to piece together what some the logic did, and how to convert it over to 2022 NGO. The Unity migration guide has been really useful, but doesn’t mention everything.
Its a Host/Client setup, where the host is running the game server for the clients to join to, and also acts as an observer to display player locations and status, as well as issuing commands. In our old code, we inherited the NetworkManager, and added logic to it.
In the old UNet code, when the selected scene finishes loading, the server does 2 things:
It makes a call to ClientScene and calls AddPlayer, and looks like it references itself for a connection.
It then tells the NetworkServer object to SpawnObjects.
Any idea what those commands translate to to NGO, and/or if they are event needed?
That can be painful. If you don’t know it already, I recommend the book “Working Effectively with Legacy Code”. Particularly if you feel struggling when making changes and other random things break and you have no idea and just want to give up …
I don’t know the UNET NetworkManager but for NGO I would strictly recommend against subclassing. Instead create separate components, one per feature / functionality ideally to keep the mental load as small as possible and make that code easier to test.
Note that NGO NetworkManager uses a custom Editor for its Inspector properties, so if you subclass and add fields those won’t appear in the Inspector.
There is no “ClientScene” in NGO. Maybe a custom class in your code?
AddPlayer would be SpawnAsPlayerObject on the NetworkObject component. The spawned object needs to be a network prefab (registered in the asset where you add all networked prefabs) with a NetworkObject component on it that you instantiate, then GetComponent() and supply that into SpawnAsPlayerObject.
Note that by default NetworkManager will use a player prefab that gets spawned automatically. It’s a convenience but I would recommend disabling. I prefer not to spawn the actual player controlled object but a sort of player manager because it will make it easier to have a central player object that always remains active so you can direct the actual player object to do something, like respawning after death, or completely changing the type of avatar the player is playing without losing any player network and local state.
Thanks, I’ll give that a try, since I’ve had to do it more than once in the past.
On the same page, already redesigned it to be that way.
No, that was in the old UNet code (Unity - Scripting API: ClientScene) , along with the method for SpawnObjects (plural). I think I recall seeing something about scenes when working through a tutorial for Netcode for Entities, but I wasn’t sure if it was the same concept.