#Disconnection Callbacks

1 messages · Page 1 of 1 (latest)

sinful chasm
#

I think you may be misunderstanding how these callbacks work and when they fire.

#

Are you trying to see if the host disconnected through the ID on a client's instance?

#

That will never work.

#

but when host disconnects then it shows a client id of 1 disconnecting not 0

The reason you're seeing this is because when the host disconnects this is the following flow that occurs:

Host DC -> Server Stops -> Disconnects all clients -> Client with ID of 1 is disconnected -> OnClientDisconnectCallback fires with an ID of 1

#

If you are a client and the Host disconnects, OnClientDisconnectCallback is just firing to tell you that the local client has disconnected.

last spoke
#

ok i do understand this, but may I direct you to the tutorial were i am learning from?

sinful chasm
#

Sure

last spoke
#

💬 Here is the Multiplayer Course! I really hope both of these FREE courses help you in your game dev journey! Hit the Like button!
🌍 Course Website with Downloadable Project Files, FAQ https://cmonkey.co/freemultiplayercourse
🎮 Play the game on Steam! https://cmonkey.co/kitchenchaosmultiplayer
❤ IF you can afford it you can get the paid ad-free ...

▶ Play video
#

everything else i have been understanding but this one part

sinful chasm
#

I'm not sure how whatever he is doing there is working on his end.

#

It's made clear in the docs that this callback only fires for the server or if the local client disconnects. Meaning that clients never have this fired when other clients disconnect.

last spoke
#

so instead use onconnection event instead

sinful chasm
#

Either will work, but yeah, it is reccomended to use OnConnectionEvent instead.

#

Really I wouldn't follow the way he's doing it in the tutorial anyway. It's overcomplicating things. You should never really need to check IDs on disconnection unless you want to display a message.

#

You should just use something like OnClientDisconnectCallback/OnConnectionEvent. If the client DCs manually, store that in a boolean. Then inside of OnClientDisconnectCallback you can check that boolean.

#

If it's true, you know you requested the disconnect. If it's false, you know you didn't request to disconnect, and to show "Host Left" UI.

last spoke
#

ok sorry for the late reply I will give this a shot