- Home /
The question is answered, right answer was accepted
[PUN] Leaving room won't delete player on LeftRoom()
So when the player clicks the "Disconnect" button it loads them into the main menu but leaves their character behind, and leaves a random player with the player's character to control at the same time. Is there anyway to delete the disconnecting player's character so this doesn't happen.
Please add what acutally happens when you press that button. How do you load the next scene? What version of pun are you using?
Sorry work got in the way for a bit, but to answer your question when I press the disconnect button I call a function called DisconnectPlayer() and in this it hits a StartCoroutine(DisconnectAndLoad()); and this coroutine has photonnetwork.leaveroom(); and I have a while loop that stops and waits till PhotonNetwork.InRoom returns null and then I use the scene manager to load my menu screen. I should also be on the latest version of PUN.
Answer by PRDarkSide · Jun 17, 2019 at 12:41 AM
OK, GOOD NEWS! I have figured it out. So in one of my room scripts I had a OnPlayerLeaveRoom which had a Player parameter called otherPlayer. I used this to utilize the PhotonNetwork.DestoryPlayerObjects class and used otherPlayer as the parameter for that and it did the trick. Thanks to all that helped.
And this does sync it across all clients even when the master client disconnects and the host is migrated.
Answer by NoCandyIncluded · Jun 01, 2019 at 03:11 PM
When the button is pressed, call the Destroy method or SetActive to false. For example.
Destroy(GameObject.Find("[NAME OF GAMEOBJECT]"));
or
GameObject.Find("[NAME OF GAMEOBJECT]").SetActive(false);
This will not work for his issue. When using Photon PUN destroying or setting inactive will not sync over the network but rather throw exceptions.
Oh, I didn't realize this, my bad. Thanks for pointing that out.
Follow this Question
Related Questions
How can I add a acharacter to a 2d game? 1 Answer
2d Character movement script (unity 4,3) 2 Answers
Is possible to spawn 2d image in photon networking ? 1 Answer
cant jump in 2d? 4 Answers