Hey guys, I always run into a problem which is undoubtedly a workflow issue on my end,
But when playing back to back matches, The player that was previously a host is unable to host a second time without restarting the app or editor, but is able to ping pong back and forth as host and client.
I believe this is something to with, even though I always use the network scene manager to change scenes.
When disconnecting a client the network managers connection to persistent managers like don’t destroy on load game managers, is unaffected, but when disconnecting the host with shutdown, its connection to network objects is severed causing errors like:
System.InvalidOperationException: An RPC called on a NetworkObject that is not in the spawned objects list. Please make sure the NetworkObject is spawned before calling RPCs.
or
[Netcode] Failed to create object locally. [globalObjectIdHash=123456789]. NetworkPrefab could not be found. Is the prefab registered with NetworkManager?
Failed to spawn NetworkObject for Hash 123456789
When interacting with the game manager after having already hosted.
What is the correct expected way of ‘Resetting’ and disconnecting a host when keeping persistent objects and scenes in mind?
Would appreciate any insight at all guys, Thanks for your time.
Never load a scene with the NetworkManager already in it. Put it in a “launch” scene.
Don’t ever destroy the NetworkManager. If you do, you probably do so because of loading a scene with the NetworkManager in it.
Upon shutdown, wait for IsListening to become false before doing anything else with the NetworkManager. This goes primarily for the host which may have to wait for clients to report back about having disconnected.
A bit too late but yeah: first order of business for any Netcode app is to establish the flow of the app. Launch, menu scene, enter game, leave game, start again. If you have this right from the start it will be tested and any issues will become apparent rather soon. If you wait for this until you finish the game and then try to get the flow working … you’re in for a treat. You will pay for the weeks or months of neglecting this flow.
Likewise if you do have this flow established and there’s an error popping up: never ignore it! Always try to get behind it.
As to the errors, make sure you search for them specifically. And not just google but also go to the Netcode Github repo and search for these errors (including closed issues). Because these discussions may reveal some insights as to why these happen, or whether it’s worthwhile to upgrade NGO.
Hey Smile,
This did lead me down quite an interesting rabbit hole,
Do you know in journey to the centre of the earth where they climb down a deep cave, leading to caverns that go down deeper and deeper to a new world, lost in time before eventually finding themselves back on the surface in a different country.
That’s my rabbit hole, I went deep, understand much more but came back up in a different place and still understand comparatively nothing
'Don’t ever destroy the NetworkManager. ’
I was thinking, because restarting the app seems to be the only certain way of hosting a second time, Maybe destroying the network manager after hosting was the right way to go. Turned out to be very tricky and gives me more errors that I hadn’t seen before but luckily you said that before I delved too far down that route.
But it did confirm to me that I hadn’t been doing so before accidentally at least
For others though this was helpful for finding the hash owner of objects erroring,
Though still not actually sure why, In my case my game manager and lobby managers network objects only seem to de spawn when an rpc is called on them, Only after having been a host previously and trying to do so a second time in a row without restarting.
Speaking or rabbit hole, I’m starting a tutorial series / project where I’ll explain how (with rationale) I set up a project for actual production use from scratch, avoiding all the common Netcode issues that I picked up from here and my own experience.
The goal is to provide a multiplayer project template that’ll work for any kind of Netcode project.
I’ll start posting articles on my blog by next week.
That is a great idea, Can’t wait.
I hope it turns into a gold mine for you too!
NGO brings so many new people into networked games but without the normal foundation for it, So like me It’s very easy to build something above your ability to debug or maintain and get frustrated or build hacks on hacks because the tutorials are designed to get you walking quickly but aren’t really geared towards production or live ops and it’s hard to notice
It’s easy to get started but as they say, multiplayer development is “five times harder” it also means it’s five times easier to fail. The introduction material doesn’t scale at all.
Just for ref and closure, I’m pretty sure that my back to back hosting issue was fixed by changing my await orders, Seems its quite lenient with the first host session and all client sessions,
But much stricter with back to back hosting, being more rigid with that seems to have fixed it.
I also abandoned all disconnecting clients with rpcs and just used shutdowns on both sides too
I think some games only have a launch scene and game scene. With the rise of procedurally generated maps,im thinking they often transitional scenes(only launch and game scenes maybe). Since our spawn point remains consistent, should we consider using prefabs for levels?
I’m trying to find out answer for this And host’s progress tracker logic(like what we managed to do in that round sync that to everyone (not player dependent, it’s like a group goal and progress, etc. etc.)