Error in tutorial (PUN)
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Error in tutorial (PUN)
Djo
2019-10-20 09:08:15
Hello,
I'm actually getting an error at this part of the tutorial "4 - Game Manager & Levels"
At "Loading Arena From The Lobby" at 3.
Everything seems to work except when i click "Leave Room" button i get this error : "Operation LeaveRoom (254) not allowed on current server (MasterServer)"
(also i need to click a second time for the button to work, no idea why)
Please some help.
Sorry if i'm not giving much informations, tell me what you need, i Don't want to send too much useless ones.
Comments
Please tell me what you need as informations and i'll try my best to explain more or send more files, please i can't find any existing post about it anywhere :neutral:
Hi @Djo,
Thank you for choosing Photon!
It looks like you are clicking "Leave Room" button too early or too late.
Too early: the client did not finish joining the room.
Too late: the client already finished joining the room.
The thing is: the button "Leave Room" should be interactable (or active or visible) only when the client is joined to a room.
@JohnTube wrote:
Hi @Djo,
Thank you for choosing Photon!
It looks like you are clicking "Leave Room" button too early or too late.
Too early: the client did not finish joining the room.
Too late: the client already finished joining the room.
The thing is: the button "Leave Room" should be interactable (or active or visible) only when the client is joined to a room.
Thanks for the answer ! Can i send you the project with the scripts ? So you can check out directly ?
In console i get these console logs before the error =>
1 - "OnJoinedRoom() called by PUN. Now this client is in a room.'"
2 - "We load the 'Room for 1'"
these 2 logs ^ are as intended in tutorial, the leave room button is active/visible only after that (but i Always have to click once on it, does Nothing, then click again and then the error appear and the game stop and pause) =>
"Operation LeaveRoom (254) not allowed on current server (MasterServer)"
I didn't see that (yellow)error before it was no visible, maybe it will help :
PhotonNetwork.CurrentRoom is null. You don't have to call LeaveRoom() when you're not in one. State: ConnectingToMasterserver
it happen just before the red error
So if i only hit the button once, Nothing happen (Nothing in console also), even if i wait.
But "PUN Basics Tutorial/Launcher: OnConnectedToMaster() was called by PUN" do happens,
this is the order of console log :
1 - "PUN Basic Tutorial/Launcher: OnConnectedToMaster() was called by PUN"
2 - "PUN Basics Tutorial/Launcher:OnJoinRandomFailed() was called by PUN. No random room available, so we create one."
3 - "PUN Basics Tutorial/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room."
4 - "We load the 'Room for 1'"
5 - yellow error"PhotonNetwork.CurrentRoom is null. You don't have to call LeaveRoom() when you're not in one. State: ConnectedToMaster"
6 - red error"Operation LeaveRoom (254) not allowed on current server (MasterServer)"
So a room is created at 2 and i join it at 3 so i Don't understand why i'm no more in a room at 5
By the way 5 and 6 happen only when i click a second time on the button.
I did check the 2 last part of the tutorial scripts to check if i had Something wrong but it seems ok, maybe i should check the entire tutorial scripts again?
I'm thinking maybe Something happen during that first click but Nothing in console.
maybe it leaves the room in the first click and Nothing happen in console … i d'ont know i'm pretty new to all of this.
Also i should say i did only one thing differently than the turorial was doing the project in 2D and panels are in canvas, but everything was working until that leaveroom error.
The first click is actually working and the client is leaving the room.
You just do not notice it in the logs or in the UI or scene loading for some reason.
When I tested the final version of the demo provided in the package when I click "Quit Room" I go back to the Launcher scene where I have to re-enter my name.
This is done in GameManager.OnLeftRoom
, note sure if it's in the tutorial or not, if it's not, we will add it:
/// <summary>
/// Called when the local player left the room. We need to load the launcher scene.
/// </summary>
public override void OnLeftRoom()
{
SceneManager.LoadScene("PunBasics-Launcher");
}
public override void OnLeftRoom()
{
SceneManager.LoadScene(0);
}
This is what i have in my GameManager and in tutorial i Believe, i also tried replace with the one you just send and it still does the same error, sorry if that's annoying and thanks for your interest.
can i get the final version of the demo too ? with all scripts ? it could actually help a lot for me to compare
i tried to put a debug log into OnLeftRoom() to see if that happen
but Nothing appear in console during the 2 clicks on Leave button in game.
i Don't remember doing anything about a "SceneManager" in the tutorial btw, maybe it's a script missing ?
What PUN version are you using?
In PUN2, you can find the demo with all scenes and scripts under "Assets/Photon/PhotonUnityNetworking/Demos/PunBasics-Tutorial/Scenes".
PUN2
Yes i got it, the demos assets :smile: going to check that out and give feed back when i figure out thanks.
Ok so i tried my best to figure out what was the error by comparing the tutorial with the actual demo...
Problem is that the demo is made differently (a small part but still…) than what is done in tutorial… and i will not lie, that's very annoying at the least.
Did you guys even try once your own tutorial ? I don't think so.
So i'll try to re-do all the tutorial from the begining and see if that happen again...
introduction - Importing PUN And Setup ->
"New accounts get an "AppId" right away. If your mail address is already registered, you are asked to open the Dashboard. Login and fetch the "AppId" to paste it into the input field."
Before login and fetch the "AppId" we have to create one… when we create the AppId in the Dashboard it's by default "Realtime" i guess we have to change it to "PUN" ?
Hi @Djo,
Read about this here.
So i'll try to re-do all the tutorial from the begining and see if that happen again..
Thank you for your understanding and for your help.
Hello and thanks again for the help,
Ok so basically, Realtime is part of PUN ? or the opposite ? (sorry i forgot to mention that English is not my first language, i'm not sure here)
I saw in the link "PUN has more high level out-of-the-box features" and "PUN adds many comfortable features for Unity and makes Realtime even easier"
So we should put the project in "PUN" for this tutorial (in the apps Dashboard) ?
Btw my first project for the tutorial was in "Realtime" it could have been an issue ?
I'm sorry too for being a little bit emotional, codes can be frustrating especially when you Don't find or understand Something ^^ I really tried to compare but i ended up with a mess trying to change my project without finding a solution, demo is almost exactly same but with some little differences that can be confusing for a beginner like me.
So Yes i'm starting a clean empty new project while of course importing PUN (and this time in 3D not 2D, to be sure), will do my best step by step and will come back here ;) i'll be happy to help if i can.
I'm having the same problem, though I load Room for 4 when I try to leave. My first thought is, how is isConnecting being set to false?
Not related to the initial error but :
Something is wrong here, and it's confusing => 2 - Lobby UI => Creating The UI For The Player's Name
6 - Add the PlayerNameInputField Script we've just created to it
7 - Locate the On Value Change (String) section inside the InputField Component
8 - Click in the small '+' to add a entry
9 - Drag the PlayerNameInputField component into the field
"PlayerNameInputField" is a script, not a component.
10 - Select in the dropdown menu the PlayerNameInputField.SetPlayerName under Dynamic String section
If we really try put PlayerNameInputField.cs into the field then there is no such things like "Dynamic string" or "SetPlayerName"
But it works if we drag the game object "Name InputField" instead.
Maybe should be fixed.
3 - Game Scènes => Quit Room Button Prefab
"Set the vertical Anchor Presets to top and horizontal anchor preset to stretch while holding Shift and Alt."
This is extremly confusing.
Firstly, there is 0 indication about vertical or horizontal in the Anchor panel except some red lines
Secondly, we have to hold Shift and Alt only for "horizontal" Anchor ? or both ?!
And finally you can't set Vertical Anchor to top because it's only for horizontal,
for "vertical" there is only left, center, right, stretch……………
As far as i know that is horizontal : ___
and that is vertical : l
Ok so i figured out for the anchors and i guess the vertical red lines means horizontal anchors…
I'm not sure about that.
I also did not get the master client error from before at the same state of the tutorial, so it was probably coming from the fact i made the project in 2D at first or maybe the anchors or also maybe the Dashboard app project in "PUN", these are basically the 3 things i made differently, also not getting the 2 click button issue.
So now everything is fine i guess except the 2 last thing i mentioned in this thread (2 last messages before that)
@jwehr wrote:
I'm having the same problem, though I load Room for 4 when I try to leave.
Do you mean the "Operation LeaveRoom (254) not allowed on current server (MasterServer)" error ?
If that load Room for 4 when you try leave, check maybe the OnLeftRoom() callback in GameManager.cs and be sure it does "SceneManager.LoadScene(0);"
Hi @Djo,
GetComponent<PlayerNameInputField>()
.
Or maybe you tried to drag the script from the project window and not from the component attached to the GameObject.
Anyway here is an animated gif:
Here is another animated gif:
Hello,
That's true, i was actually thinking about it ( i mean a script can be a component obviously )
Yes that's what i tried to do :sweat_smile:
My version was 2019.2.0f1 and i'm going to update but it works by doing what you did show in the gif.
I'm not sure if you should change it because it actually works but it can be confusing and could make people try to drag the script from project window like me because the repetition and the lack of precision in the actual instructions.
Maybe Something like that : "Drag the PlayerNameInputField component you just added, into the field"
Yes i think that's way better like that, it make a lot more sense, could really help.
I did get the good result at the end but it was very confusing with the actual tutorial instruction.
Thanks for all, i'm now unstuck, things make more sense now, can continue the tutorial <3
Kinematics
2020-04-15 05:56:55
@Djo no longer has this problem (I am glad for them but still very sad for me!) and listed the following things as possible sources of the resolution:
"I also did not get the master client error from before at the same state of the tutorial, so it was probably coming from the fact i made the project in 2D at first or maybe the anchors or also maybe the Dashboard app project in "PUN", these are basically the 3 things i made differently, also not getting the 2 click button issue."
However, I (a) am making a 3D app to begin with, (b) already had the Dashboard app set to "PUN", and (c) didn't have any trouble with the button anchors (this last one seems unlikely to be the source anyhow). @Djo, can you think of any other things that changed?
I know I'm resing this thread after a few months, but I have exactly the same problem and the solution is just "welp, it works now somehow". This is, of course, fine for Djo, but since the tutorial literally the starting point for new Unity users I would appreciate another crack at this from the Photon team...
It seems to me that PhotonNetwork.LeaveRoom();
is never triggering OnLeftRoom()
. This is consistent with @Djo's observation that you can then click the button a second time and get the "can't leave MasterServer" error -- because you've already left the room successfully but the scene hasn't been changed so we still (wrongly) have access to the button for leaving the room!
I could get the OnLeftRoom
callback to work by moving it over to the Launcher script (along with using UnityEngine.SceneManagement
and make sure the Launcher game object is not destroyed on load. Then the first join and exit work perfectly --- which again reinforces my suspicion that the callback is not being accessed for me using the tutorial setup. (This approach leads to other errors if I keep loading and saving, I was just exploring what's causing the original bug...)
@JohnTube mod any thoughts what might cause us to skip the callback like this?
Thanks
p.s. I'm running 2019.3.1f7, and (according the docs in the Photon asset folder) PUN2 2.17
Hi @Kinematics,
Thank you for choosing Photon!
So you are asking why OnLeftRoom is not called after calling LeaveRoom?
well it could be many reasons:
A. LeaveRoom call is not successful
- check logs after calling LeaveRoom, maybe you were not in a room in the first place?
- check return value of LeaveRoom if any.
B. LeaveRoom all is successful:
- callback not implemented properly (no callback interface IInRoomCallbacks or not extending class that implements that interface, class like PhotonMonoBehaviourCallbacks)
- class implementing callback is not registered (AddCallbackTarget not called, overriding OnEnable without calling base.OnEnable)
- class implementing callback unregistered before callback could be triggered (OnDisable called which trigger RemoveCallbackTarget)
- class implementing callback is no longer available (scene changed?)
Is any other callback called after calling LeaveRoom?
For example OnConnectedToMaster?
Kinematics
2020-04-15 15:41:11
Thanks for the fast reply @JohnTube!
Some of that list obviously doesn't apply to my situation (we can already infer LeaveRoom is working by the error produced clicking it a second time; I'm following the tutorial and thus inheriting from MonoBehaviourPunCallbacks; Not changing the scene is my whole problem) but it's actually quite nice to have that full debug list for future reference.
In this case my idiocy was exactly B.2: after turning the GameManager into a prefab, I forgot to instantiate it back in the scene.
Since the "leave room" button directly referenced the script, PhotonNetwork.LeaveRoom
still got called, but since it wasn't attached to any game object there were no registered callbacks.
Thanks again for the speedy help!
Hello, following I'm currently following this tutorial and had the same issue.
It should be addede to the tutorial when we create the prefab from GameManager in Chapter 3 Game Manager Prefab: "Turn Game Manager into a prefab by dragging it from the scene Hierarchy to the Assets Browser, it will turn blue in the Hierarchy." ....and don't delete this prefab from the Hierarchy.
Maybe this will help to avoid this error by another users. It kinda silly but i thought that when we change something in the prefab in Assets and it will be called by UI button in the scene without adding it to the Hierarchy.
Hello friends, I also have the same problem. In my case with version 2019.2.2.1f1 of Unity and PUN 2, the case is that I am testing the functionality of PUN Basics Tutorial, and it is wrong. In my case, it is when I connect to the game with two players, I build in .exe mode, and I execute two instances with different names, it creates the room for me and the players begin to fight with the laser, when one of the players ends his life , that's when the error occurs.
I get an error in the update function when it leaves the room automatically from the PlayerManager.cs class
public void Update()
{
// we only process Inputs and check health if we are the local player
if (photonView.IsMine)
{
this.ProcessInputs();
if (this.Health <= 0f)
{
GameManager.Instance.LeaveRoom();
}
}
if (this.beams != null && this.IsFiring != this.beams.activeInHierarchy)
{
this.beams.SetActive(this.IsFiring);
}
}
Back to top