Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon Networking Guide

Discussion in 'Multiplayer' started by bertelmonster2k, Mar 21, 2012.

  1. neoRiley

    neoRiley

    Joined:
    Dec 12, 2008
    Posts:
    158

    Can you please share what the fix was?? You mention in your edit that it was working later, but I'm getting this error now, and I can't get rid of it ;)

    Thanks very much,

    John
     
  2. TheStone

    TheStone

    Joined:
    May 18, 2013
    Posts:
    77
    Look for this method and add the code as I did.... it is wierd, that this guy in the forum says in 2012 is going to fix it in the next release... but never did, or did no know how... :confused:

    void OnReceivedRoomListUpdate()
    {
    Debug.Log("OnReceivedRoomListUpdate");
    Debug.Log("We received a room list update, total rooms now: " + PhotonNetwork.GetRoomList().Length);

    string wantedRoomName = "TestRoom" + Application.loadedLevelName;
    Debug.Log("wantedRoomName = " + wantedRoomName);

    foreach(RoomInfo room in PhotonNetwork.GetRoomList())
    {
    if (room.name == wantedRoomName)
    {
    PhotonNetwork.JoinRoom(room.name);
    Debug.Log("PhotonNetwork.JoinRoom(room.name);" + room.name.ToString());
    break;
    }
    }

    }

    Enjoy it!!! :D
     
    romya0010 likes this.
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    The error could actually be an expected one, which just belongs into the workflow.
    If you try to create a room that's already existing, you can't just steal the name. Instead, you could join the room or come up with another name.
    The workflow is explained briefly in the "Handling Errors" section of the Marco Polo tutorial as well:
    http://doc.exitgames.com/photon-cloud/Marco_Polo_Tutorial
     
  4. Fran_Codigames

    Fran_Codigames

    Joined:
    Jun 19, 2013
    Posts:
    1
    This is unacceptable, most examples do not work with Unity 4.
     
  5. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    How so? For me all examples work under U4. I don't know of any incompatabilities between U3 and U4 in regards of PUN.
     
  6. sylvain

    sylvain

    Joined:
    Feb 19, 2013
    Posts:
    46
    Hi,

    I just bought and download your tutorial, and as others, I have an error on Tutorial 2A1, under U4. The second player cannot connect to the room, and got an :

    createGame failed, client stays on masterserver: OperationResponse 227: ReturnCode: 32766 (A game with the specified id already exist.). Parameters: {}.

    I have read this thread, but I don't understand what to do, or which fix to do. Could you please help me ?
     
  7. Somemen_Ice

    Somemen_Ice

    Joined:
    Jul 4, 2012
    Posts:
    5
    I love this guide so much,but i got a problem about the Example4 FPS Game,i change the Example4_Menu by use Example3_lobbymenu instead Example2_Multiplayer menu,when i hit play,everything's fine.But when i hit the stop button,i got the error like Failed to 'network-remove' GameObject because it's null. can you help me

    $Error.jpg
     
  8. sylvain

    sylvain

    Joined:
    Feb 19, 2013
    Posts:
    46
    I think I have found : I have transferred all the code from OnReceivedRoomList() to OnReceivedRoomListUpdate(). It works for me. Is it the right solution ?
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    sylvain: I can't see where you posted what you do now in OnReceivedRoomListUpdate() but if it's working for you, this should be ok.

    There is a simple mechanism to join a random game or create one with a random (automatically assigned) name:
    http://doc.exitgames.com/photon-cloud/MatchmakingAndLobby/
     
  10. Somemen_Ice

    Somemen_Ice

    Joined:
    Jul 4, 2012
    Posts:
    5
    I solved the problem by change the "Example3_Menu_Lobby" script's LaunchGame function to below function,but i don't know how it works than before



    [RPC]
    void LaunchGame()
    {
    LaunchingGameGUI();
    //launchingGame = true;
    }
     
  11. TheJeepee

    TheJeepee

    Joined:
    Jul 19, 2013
    Posts:
    1
    Hello there,

    If you use Photon networking can you play multiplayer games with 3G. Unity networking use only wi-fi and tablets games cannot be played with 3G
     
    Last edited: Jul 19, 2013
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Networking on 3G is very limited and in worst case not very stable.
    There is no guarantee it's working nicely and consistently but if you minimize updates/second and traffic, you should be able to get it going.
     
  13. Roboz

    Roboz

    Joined:
    Aug 10, 2013
    Posts:
    2
    I've got to be honest, this package is pretty disappointing for the price. Most of the examples seem to have major issues that cause them to not work properly. The FPS Example (probably the most appealing to people) doesn't work. When I run it the game throws an error saying the player prefab has no rigidbody, adding a rigidbody causes the player to fall through the floor. When I try to connect with a second client one of the players times out for no apparent reason and gets booted to the server select screen again. From the reviews it sounded like this would be a great headstart to networking, but it's just been a huge waste of my time so far trying to debug someone else's code.
     
  14. MarceloRay

    MarceloRay

    Joined:
    Jul 6, 2012
    Posts:
    1
    Thanks Sylvian, after a day spent searching for a solution, this was the only one that worked for me.
     
  15. DMTSource

    DMTSource

    Joined:
    Jul 11, 2013
    Posts:
    36
    The tutorials/sample code on the photon site are still showing the old code, was a pain but finally came across this post.

    Ex:
    http://doc.exitgames.com/en/photon-realtime/PhotonUnityNetworkingIntro#_connectpun

     
  16. marsbear

    marsbear

    Joined:
    May 12, 2010
    Posts:
    3
    Same here. OnReceivedRoomList does not get called but the Connect1C script relies on it to join the room for all but the master client. Hence all further clients get a 'room already exists' error.

    This error is known for months now and hasn't been fixed :/ Took me some time to figure it out.
     
  17. dceevp

    dceevp

    Joined:
    Mar 4, 2013
    Posts:
    19
    Hi!
    I am interested in buying this guide to setting up my game, but I think this guide is oriented to Photon Cloud.
    Is there a basic guide with Photon server, adding logic from the server, an example type "hello world"?
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
  19. dceevp

    dceevp

    Joined:
    Mar 4, 2013
    Posts:
    19
  20. technicalclap

    technicalclap

    Joined:
    Mar 13, 2014
    Posts:
    1
    Hi,
    I found an issue with JoinOrCreateRoom() in Connect1C.cs. It was trying to create a room after joining a room.

    The problem seems to be that PhotonNetworking.room is still null for awhile after JoinRoom is called, so there is a race condition in JoinOrCreateRoom.

    I solved the issue by adding a wait for the room reference after receivedRoom has been set, but before the CreateRoom block:

     
  21. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Thanks, never experienced this myself. I've corrected this and it will be included in the next update.
     
  22. thorskull

    thorskull

    Joined:
    Jun 5, 2013
    Posts:
    21
    Hello there, hoping Mike or one of the other Photon admins can answer this.

    I work in a program that currently uses OpenSim extensively in our day to day business. Currently we own several OS grids but are looking into switching them over to Unity; I'm currently researching options for Unity development and ran across the Photon assets. At first glace I would need more info before being able to see if Photon could work.

    We would need basically the same capability OS offers including "grid" chat, private messaging, and most importantly large meeting capability. We occasionally hold conferences in the grid that can hold up to 200 people. This combined with the messaging and other features would obviously be extremely taxing on any server type system. So I was wondering if just from this info if Photon would be able to support this at all if possible. Thanks!
     
  23. ThePhotons

    ThePhotons

    Joined:
    Aug 30, 2012
    Posts:
    8
    Please write us to developer@exitgames.com.

    Chris
     
  24. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Updated the guide to the lastest PUN (1.25b) and included a new, free, extra: A network culling system that I used in our FPS game Verdun. It helped us reduce network messages by 50%.

    For more details about the culling, see:
    http://www.m2h.nl/network-traffic-culling/
     
    Last edited: Jul 17, 2014
  25. yung

    yung

    Joined:
    Nov 22, 2010
    Posts:
    274
    @MikeHergaarden
    I've sent you an email, regarding the network culling.
     
  26. AlteredPlanets

    AlteredPlanets

    Joined:
    Aug 12, 2013
    Posts:
    455
    is it possible to have users in your game play for custom servers?
     
  27. marsbear

    marsbear

    Joined:
    May 12, 2010
    Posts:
    3
    Hey Guys,

    I am working on a multiplayer project and switched to developing on a Mac. I built the project as MacOs Universal application and photon refuses to connect to the server when I use that build. It works when started from the editor though.

    I updated to the Photon Networking Guide 1.26.

    The resulting error in the Player.log is quite strange:

    Code (CSharp):
    1. Receiving unhandled NULL exception
    2. Obtained 13 stack frames.
    3. #0  0x0000010510e9e8 in (Unknown)
    4. #1  0x00000110773f19 in  System.Net.Sockets.Socket:Receive_nochecks (byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.Sockets.SocketError&) + 0xc9 (0x110773e50 0x110773f9f) [0x109744cc0 - Unity Root Domain]
    5. #2  0x00000110773d4b in  System.Net.Sockets.Socket:Receive (byte[]) + 0x5b (0x110773cf0 0x110773e38) [0x109744cc0 - Unity Root Domain]
    6. #3  0x0000010f49781f in  (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) + 0x5f (0x10f4977c0 0x10f497882) [0x109744cc0 - Unity Root Domain]
    7. #4  0x00000101a6f3a4 in mono_jit_runtime_invoke
    8. #5  0x00000101b92027 in mono_runtime_invoke
    9. #6  0x00000101b96d6d in mono_runtime_delegate_invoke
    10. #7  0x00000101bbd17c in start_wrapper
    11. #8  0x00000101bec0ad in thread_start_routine
    12. #9  0x00000101c121bc in GC_start_routine
    13. #10 0x007fff901b9899 in _pthread_body
    14. #11 0x007fff901b972a in _pthread_struct_init
    15. #12 0x007fff901bdfc9 in thread_start
    16. Symbol file LoadedFromMemory doesn't match image <snip>/builds/AiS MacOS 64bit.app/Contents/Data/Managed/UnityEngine.dll
    17. Symbol file <snip>/builds/AiS MacOS 64bit.app/Contents/Data/Managed/UnityEngine.dll.mdb doesn't match image <snip>/builds/AiS MacOS 64bit.app/Contents/Data/Managed/UnityEngine.dll
    18. Creating room: TestRoom-1
    19. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    20. UnityEngine.Debug:Log(Object)
    21. <JoinOrCreateRoom>c__IteratorF:MoveNext() (at <snip>/Assets/_Scripts/NetworkHub.cs:223)
    That 'doesn't match image' message bugs me. I double checked the project for UnityEngine.dlls but there are none in the assets folder. I thought it might be other plugins so I stripped all plugins I just tested from the project. After that I created an empty project and only imported the Photon Networking Guide, to no avail. The issue remained.

    What fixed it:
    I switched to a MacOS 32bit build and suddenly it works.

    This is easily reproducible (New Project->Import Photon Networking Guide->64bit Build->Broken).

    Do you have any hints on this issue? I can't tell if it used to work in older versions of the guide as I didn't try to build on Mac back then.

    Best regards
    Marc
     
  28. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @marsbear: Right, at the moment you can only build x86 applications for Mac. I am not sure yet if it's a Unity issue or one on our side.
    In theory, C# defines how each type behaves, no matter if 32 or 64 bytes.
    In best case, you report this as bug to Unity.
     
  29. jtadeo1

    jtadeo1

    Joined:
    Oct 18, 2006
    Posts:
    78
    Hi Everyone,

    Can anyone tell me a bit more about this guide? I'm looking to expand my knowledge of Photon and curious to see the quality of the information. I know the writer was well regarded but when I read the comments at the asset store, they were less than sterling.

    Basically, is this guide worth the $60?

    *Let me clarify - I've read the reviews but apparently the issues have been fixed. Just wondering if it got better because of it. Much of the complaints related to code not working.
     
    Last edited: Oct 15, 2014
  30. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    tobiass how is it possible for collision detection with tags without confusing with the tags in the network?i mean if u are in the game with 2 clients and photonvie.ismine object has tag player and the other one with tag enemy? how is the enemyone in the scene of the where he is enemy (photonview not mine) is going to detect collision of the other? its going to detect the collision if its a sword kind of thing...
     
  31. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    The reviews are indeed not so good at the moment, but all are indeed addressed. I'm not aware of any open issues. If there are any open issues I'll be fixing themright away.
    As for the price, do note that it includes a 100 CCU PUN cloud membership, which already justifies half of the price or so.
     
  32. marsbear

    marsbear

    Joined:
    May 12, 2010
    Posts:
    3
    tobiass: Thanks for your reply. The thing is, it works with other libraries. Another one of my projects does not use Photon but Vectrosity and that project compiles and runs fine even for Mac 64bit. The stack-trace pops up when I start to connect to Photon Cloud so maybe some issue with underlying network code from Mono on Mac? Just a wild guess :)
     
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @marsbear: That's my guess, too. I will have to get in touch with Unity.
    Thanks for the heads up.
     
  34. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    Hi @MikeHergaarden.. @tobiass
    I would like to ask about the Networkig culling from the Photon Networking Guide.
    This "network culling" in someway affect the accuracy, precision and Smooth moves?
    What abount the performance implementing the "network culling" in 2D games?


    Thx!
     
  35. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    It will simply send the OnSerialize updates less, based on distance from your own player/camera. So the updates are less freqent, (3 or 5 times a second instead of 10 times a second for example)

    Should work just fine for 2D games, since in my example I only use X and Z axis too, you could change this to X and Y, or just 1 axis really.
     
  36. danish115

    danish115

    Joined:
    Aug 28, 2014
    Posts:
    47
    hi everybody ... i want to play the game Play scene when there may be more than one and less than 5 players are in room anybody can tell me how is it possible. i also want to check the time. after that time will over more than one and less than 5 players automatically play the game play scene .... i have searched all the way but there is no clue hint or anything related to my problem. i think the photon only supports that player enter in game play scene one by one. i have never found any example like more than one player enter the same room and play the game play scene simultaneously. if there is any demo, tutorial or anything else can u refer me according to this type of issues or photon may not support this ?? In both case please do let me inform ??
     
  37. danish115

    danish115

    Joined:
    Aug 28, 2014
    Posts:
    47
    Anybody there ??
     
  38. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    I'm not sure who is supporting this asset, but i'll just tag a few people: @tobiass @MikeHergaarden @bertelmonster2k

    So I purchased this asset sometime ago mostly for the Network Culling Script. I've added the Network Culling to my project, and It was setup correctly I believe according to your instructions in the guide.

    I noticed that Networking Culling is killing my performance rather than improving my game. If I disable the Network Culling component on my Players and AI I notice a huge performance gain! We are talking about a 200-400 FPS (fluctuating) w/ Networking Culling enabled, to 700 FPS (average) w/ Networking Culling Disabled. (Testing from Unity Editor)

    How do I begin to debug this? Where do I look to find any issues with the Networking Culling setup? All I know right now is it's killing my game performance, so I disabled it for now. I'm hoping to make use of it to help reduce latency from my game by limiting the amount of messages sent / received between clients.

    Please advise on how to begin troubleshooting (debugging) Network Culling. Thanks!
     
  39. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Do note that this willl ofcourse not optimize your CPU performance (per se). It's main goal is to reduce network traffic(bandwith).

    Also, a 200+ FPS range does not sound like a realistic figure to aim for, any small script would have a huge impact on a 700FPS project.
    Is your game already complete and does it need 700FPS? If not: please add some temp. assets and profile a build player (not the editor) to see the actual impact.

    I do believe you can win some performance though, I might have made some minor modifications on this script for our own game.
    You could disable some parts of the script to see where your CPU time is being used.
     
  40. Carmexx

    Carmexx

    Joined:
    Jul 29, 2014
    Posts:
    63
    Hi, couple of questions:

    re Network Traffic Culling - does it still work for the latest pun version 1.58? / latest unity version ?

    I have an example, so we have two characters, A & B. A is East, B is West, so the culling kicks in, player A moves North, and player B moves East, now does player B see a paused character A in the east, as culling is still in place as character A is way up north ? How does this work in characters seeing each other after culling has taken place and one character has moved to the other old characters position?

    thx
     
  41. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    In my simple culling system you -will- know that the other character has moved because there is still 10% of the normal rate of updates. So it never fully disables, only greatly reduced the amounts of updates.
     
  42. Carmexx

    Carmexx

    Joined:
    Jul 29, 2014
    Posts:
    63
    Hi,

    Works fine for players, very good job Mike. Quick question on adding the script to AI, is this possible somehow?

    If I add the script to AI, the master clients traffic goes crazy, literally thousands of updates per second, its probably what the guy a few posts above (Kuroato) experienced, bad stuff. I'd imagine as the AI run on the master, there's a group conflict, the master client must somehow get all the groups assigned at the same time, some kind of exponential traffic is occurring.

    I know you never mentioned anything about AI, the script does the job you said it would, but any thoughts on AI ?

    thanks
     
  43. Hakazaba

    Hakazaba

    Joined:
    Jul 1, 2015
    Posts:
    119
    Hey, is this worth purchasing? Is it compatible with the current pun version? The reveiws on the asset store are very negative.
     
  44. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Hi is this ' Photon Networking Guide ' series up to date?

    Would just like to know before purchasing on asset store

    Thanks
     
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Sadly, it's not up to date.
    Mike didn't have much time to update it and while it's working, it is not on par with latest PUN versions.

    I suggest to check out the Marco Polo Tutorial, which is free. Soon, this will get replaced.
    Have a look at the tutorial videos of Sky Arena or PUN Rally (both have free videos).
     
  46. thendricks

    thendricks

    Joined:
    Aug 14, 2012
    Posts:
    48
    I'm having a glitch (I think) with RPC's, Here's a simple calling of my RPC. I have a photon view attached to the GameObject, it's in the settings, but it's not recognizing the RPC I'm getting 2 errors:

    Illegal view ID:0 method: UpdatePossesion GO: PossesionGameMode(Clone)
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3545)
    PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2893)
    PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:574)
    Possesion:Start() (at Assets/Scripts/Photon Multiplayer/GameModes/Possesion.cs:21)


    PhotonView with ID 0 has no method "UpdatePossesion" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: String
    UnityEngine.Debug:LogError(Object)
    NetworkingPeer:ExecuteRpc(Hashtable, PhotonPlayer) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2817)
    NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3604)
    PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2893)
    PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:574)
    Possesion:Start() (at Assets/Scripts/Photon Multiplayer/GameModes/Possesion.cs:21)


    Here's a place where the RPC is called:
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         this.photonView.RPC("UpdatePossesion", PhotonTargets.All, "none");
    4.     }
    5.  
    6.     [PunRPC]
    7.     void UpdatePossesion(string Team)
    8.     {
    9.         CurrentOwner = Team;
    10.     }
     
  47. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    The problem is likely something like you're not using PhotonNetwork.Instantiate to create (and initialize) the GO or you are not in a room yet. Wait till you got the callback for "Joined Room".
    RPCs are covered in our docs / tutorials.
     
  48. Carmexx

    Carmexx

    Joined:
    Jul 29, 2014
    Posts:
    63
    Hi,

    Seems the network culling script no longer works with the latest pun, 1) it doesn't do anything to suppress ranged, and oddly 2) when two players are next to each other, one leaves the room, comes back, it seems to believe they are very far apart and then suppresses network info - dangerous bug, took me ages to work it out.

    Is there an updated network culling Tobiass, 'I mean it's in photons interest right to help reduce traffic :) ?'
    @tobiass @MikeHergaarden
     
  49. Carmexx

    Carmexx

    Joined:
    Jul 29, 2014
    Posts:
    63
    aha never mind, I see the network culling handler etc etc - tests fine, coolio. :)
     
    tobiass likes this.
  50. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062