The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

Djo
2019-10-21 08:12:50

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:

JohnTube
2019-10-21 09:55:49

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.

Djo
2019-10-21 10:32:47

@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)"

Djo
2019-10-21 10:56:01

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

JohnTube
2019-10-21 11:14:28

Can i send you the project with the scripts ? So you can check out directly ?
No need.
also i need to click a second time for the button to work, no idea why
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
Hit the button once and wait until the client finishes leaving the room, i.e. when OnConnectedToMaster is called and the debug message is logged: "PUN Basics Tutorial/Launcher: OnConnectedToMaster() was called by PUN". If you don't see the message make sure you've done everything right in the previous steps and that scene loading and synchronization is working as expected.
PhotonNetwork.CurrentRoom is null. You don't have to call LeaveRoom() when you're not in one. State: ConnectingToMasterserver
This just confirms what I have been saying.

Djo
2019-10-21 11:33:36

Hit the button once and wait until the client finishes leaving the room, i.e. when OnConnectedToMaster is called and the debug message is logged: "PUN Basics Tutorial/Launcher: OnConnectedToMaster() was called by PUN". If you don't see the message make sure you've done everything right in the previous steps and that scene loading and synchronization is working as expected.

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?

Djo
2019-10-21 11:45:31

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.

JohnTube
2019-10-21 13:27:14

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");  
		}

Djo
2019-10-21 13:36:10

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

Djo
2019-10-21 13:44:48

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 ?

JohnTube
2019-10-21 15:31:52

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".

Djo
2019-10-21 15:50:53

PUN2
Yes i got it, the demos assets :smile: going to check that out and give feed back when i figure out thanks.

Djo
2019-10-23 22:44:03

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...

Djo
2019-10-23 23:04:06

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" ?

JohnTube
2019-10-24 09:38:09

Hi @Djo,

i guess we have to change it to "PUN" ?
Applications of type Realtime, PUN can be used interchangeably. In fact, PUN is built on top of Realtime.

Read about this here.

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.
I'm sorry, you feel annoyed by this.
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..

If you could help us by starting from a clean empty new project, importing PUN and following the tutorial step by step and letting us know what's wrong or missing, we could improve it and fix any issues.

Thank you for your understanding and for your help.

Djo
2019-10-24 12:14:20

Hello and thanks again for the help,

In fact, PUN is built on top of Realtime.

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, you feel annoyed by this.

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.

jwehr
2019-10-24 19:43:26

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?

Djo
2019-10-24 21:44:15

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.

Djo
2019-10-25 01:19:34

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

Djo
2019-10-25 03:09:35

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);"

JohnTube
2019-10-25 10:21:24

Hi @Djo,

"PlayerNameInputField" is a script, not a component.
A "script" is a component. All components are scripts.That's why you can use GetComponent<PlayerNameInputField>().
If we really try put PlayerNameInputField.cs into the field then there is no such things like "Dynamic string" or "SetPlayerName"
This is maybe the same Unity bug that we found out lately: what Unity version are you using, this bug was reproduced in 2018.4.9. Unity support said: "The issue is fixed in 2020.1.0a5. Fix is also backported to 2018.4.11f1, 2019.2.8f1, 2019.3."

Or maybe you tried to drag the script from the project window and not from the component attached to the GameObject.

But it works if we drag the game object "Name InputField" instead.
Maybe we should change "Drag the PlayerNameInputField component into the field" to "Drage the Name InputField GameObject into the field" instead.

Anyway here is an animated gif:

"Set the vertical Anchor Presets to top and horizontal anchor preset to stretch while holding Shift and Alt."
Sorry about this. It should be: "Set the Anchor Presets to the preset case with coordinates "top" (row, vertical) and "stretch" (column, horizontal) while holding Shift and Alt."

Here is another animated gif:

Djo
2019-10-25 11:37:04

Hello,

A "script" is a component. All components are scripts.That's why you can use

That's true, i was actually thinking about it ( i mean a script can be a component obviously )

Or maybe you tried to drag the script from the project window

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"

It should be: "Set the Anchor Presets to the preset case with coordinates "top" (row, vertical) and "stretch" (column, horizontal) while holding Shift and Alt."

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

JohnTube
2020-04-15 11:43:59

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

  1. check logs after calling LeaveRoom, maybe you were not in a room in the first place?
  2. check return value of LeaveRoom if any.

B. LeaveRoom all is successful:

  1. callback not implemented properly (no callback interface IInRoomCallbacks or not extending class that implements that interface, class like PhotonMonoBehaviourCallbacks)
  2. class implementing callback is not registered (AddCallbackTarget not called, overriding OnEnable without calling base.OnEnable)
  3. class implementing callback unregistered before callback could be triggered (OnDisable called which trigger RemoveCallbackTarget)
  4. 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!

Wallace92
2020-09-16 21:49:34

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.

Nanolab
2020-10-13 15:05:22

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

Back to top