Search Unity

Third Party Photon Unity Networking

Discussion in 'Multiplayer' started by tobiass, Aug 23, 2011.

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @dorpeleg: As said, the list of rooms is not immediately available. That's a known limitation you need to work with. There is a callback OnReceivedRoomListUpdate() which tells you when you get updates. This could be used to show the list after the first call.

    @Sbizz: We're using double for precision and until just now, I was under the impression that Unity also uses a double for Time.time but I was wrong. Is it a problem?
     
  2. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Not at all ! I often use float so when I call PhotonNetwork.time, I have to cast it to float. I was just curious ;)
     
  3. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    @tobiass Ok, using OnReceivedRoomListUpdate() seems to be working well.
    I just moved my create buttons method in there and now it shows as soon as I enter the lobby :)
    I have another question:
    I'm trying to display player names (not just my own) using UGUI.
    Any tips on what the best way to accomplish this? I'm struggling.
     
  4. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    nvm, I got it working...
     
  5. guiller711

    guiller711

    Joined:
    Jan 7, 2014
    Posts:
    1
    how do i make the players start at the same time? i have created a room but i need the players to start (or have enabled controls) at the same time? its racing game.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Take a look at InRoomRoundTimer.cs in the package. It stores the start time of the room in a Custom Property and uses it to start new rounds every X seconds. You can do it similarly. Store the time when the race should begin (1..2 seconds ahead of now) and the others can sync.
     
  7. D_Cergy

    D_Cergy

    Joined:
    Feb 18, 2015
    Posts:
    35
    Can I ask questions here? I cannot register in Photon Forum, I don't know why my IP detected as spammer there.

    I wanted to create room based on level. So I made one with custom properties. The room is created but, I cannot JoinRandom with RoomOptions on the different client. It always failed joining, and my code handle it to create another room. But, if I JoinRandom without any filter, the client successfully join the existing room. FYI, I'm not logging in into a lobby at this time.

    CREATE
    RoomOptions options = newRoomOptions();
    options.customRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "L", selectedLevel } };
    options.maxPlayers = 2;
    options.cleanupCacheOnLeave = true;
    PhotonNetwork.CreateRoom(null,options,null);


    JOIN
    PhotonNetwork.JoinRandomRoom(new ExitGames.Client.Photon.Hashtable() { { "L", selectedLevel } },0);



     
  8. Deleted User

    Deleted User

    Guest

    I have the same issue.
     
  9. weilieschok

    weilieschok

    Joined:
    Jan 12, 2014
    Posts:
    25
    I have got this error after download PUN+ and imported into my current project
    how could i get rid of it?
     

    Attached Files:

  10. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    You should take a picture of the console...

    Because what you took will not help us !
     
  11. DshFox

    DshFox

    Joined:
    Oct 10, 2013
    Posts:
    15
    Hi tobiass. There is more difference between PUN and PUN+ version(besides 100 CCU in photon cloud)? If there is, i would like to know all features. This 100 CCU will be available for ever(I wont use it right now, maybe next year)? In Unity Free we already have the option to compile the android version.. Thanks
     
  12. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    @tobiass Hey, I seem to have a problem calling an RPC from a base class.
    I have a class with the RPC (we will call it BaseClass) and a class that inherits from it (we will call it InheritingClass)
    My PhotonView is observing the InheritingClass but when calling the RPC
    Code (CSharp):
    1.  
    2. var photonView = collision.gameObject.GetComponent<PhotonView>();
    3. photonView.RPC("RPCmethod", PhotonTargets.All);
    4.  
    Its not working... (was working when RPC was not in InheritingClass)
     
  13. D_Cergy

    D_Cergy

    Joined:
    Feb 18, 2015
    Posts:
    35
    [Solved] I found out the problem, the function overload that create room with RoomOptions cannot be joined with filter of hashtable properties. I used another overload and it works :
    PhotonNetwork.CreateRoom(null,true,true,2,props,roomPropsInLobby);

    May I ask you an advice for a good design pattern?
    I have a prefab of character and a dummy which is have more simple structure (the dummy reflect your character on another player's game scene). So, I cannot use the method that in Marco Polo tuts explained to Instantiate the same character prefab with PhotonView in another client's scene, I used the dummy instead.
    So how do I communicate the transform of my character to be reflected in the dummy game object in other player's scene? My game consist of 2 players only. Am I using a bad approach to design a network game this way? If I was wrong, what do you guys recommend to solve this (keep using the dummy)?
     
  14. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    Quick question. I came across this photon thing in the asset store and from what I'm reading it'll allow me to have online multiplayer on my game without needing my own server? I have the wiiU developers license and I'm planning on making a fighting game for wiiU and PC. Will this help me out the way I think it will? I saw cubemen in the pictur and I know they have cross platform between wiiU and steam so I'm wondering if I'll be able to do the same thing with photon. If I purchase what else will I need besides photon to have my final product playable online?
     
  15. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    If dummy is network object with PhotonView attached, update its transform with character transform and synchronize transform over network.
     
  16. bertelmonster2k

    bertelmonster2k

    Joined:
    Apr 3, 2009
    Posts:
    78
    Yes.

    Yes. Cross Platform play is possible with Photon (Cloud). You need to verify this is OK with your Nintendo contact: They may ask you to verify identities of the users etc.

    Cubemen is using Photon / you do not need anything else.
     
  17. D_Cergy

    D_Cergy

    Joined:
    Feb 18, 2015
    Posts:
    35
    Got it, thank you so much :)
     
  18. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    Hello sirs Photon + is 50% off sale. How many days left that? When you going to remove 50% OFF? Currently I'm working on assets. I really don't want to miss this cool discount, please.
     
  19. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    What is photon pun+ ? What feature it has compared to photon free multiplayer package in asset store? and what benefits developer can earn when use it?
     
  20. plokkum

    plokkum

    Joined:
    May 28, 2013
    Posts:
    90
    I bought Photon+ over the weekend during the Asset Store sales. It seems very easy to set up.
    However, I do have a question, since I have no experience scripting multiplayer games.

    I want my master client to handle melee attacks in order to prevent some cheating. I didn't really find any documentation about this workflow, so I'm wondering if this is the way to go. If anyone could check if this is correct, I'd appreciate that!

    Also note the last RPC that is called somehow never gets executed on the Master Client. Does anyone know why?

    Code (csharp):
    1.  
    2. // First I'm sending a 'punch'-request to the MasterClient.
    3. photonView.RPC (
    4.         "Punch",
    5.         PhotonTargets.MasterClient,
    6.         transform.position,
    7.         transform.forward,
    8.         playerProperties.punchForce,
    9.         myId );
    10.  
    11. // Then I do some logic to figure out of an enemy was hit.
    12. [RPC]
    13. private void Punch (Vector3 position, Vector3 direction, float punchForce, int originId)
    14. {
    15.     if (!PhotonNetwork.isMasterClient)
    16.         return;
    17.  
    18.     // Stuff to figure out if the enemy was hit
    19.     // blabla...
    20.  
    21.     // If the enemy was hit, I'll send out the RPC to all clients
    22.     photonView.RPC (
    23.         "GetPunched",
    24.         PhotonTargets.AllViaServer,
    25.         direction,
    26.         punchForce,
    27.         enemyId);
    28. }
    29.  
    30. [RPC]
    31. public void GetPunched(Vector3 direction, float punchForce, int enemyId)
    32. {
    33.     // However, this RPC is somehow only called on the clients, not on the server. Why?
    34.     print("My id is: " + photonView.owner.ID + ", enemy hit was: " + enemyId);
    35.  
    36.     if (photonView.ownerId != enemyId)
    37.         return;
    38.  
    39.     // Other logic to handle the punch on all clients...
    40. }
    41.  
     
    Last edited: Feb 25, 2015
  21. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    You know the MasterClient is the first client who entered in the room. So someone can cheat anyway.

    You should use "All" instead of "AllViaServer"
     
    plokkum likes this.
  22. plokkum

    plokkum

    Joined:
    May 28, 2013
    Posts:
    90
    Thanks, I'll do that.
    So I guess the procedure I'm using is correct?
     
  23. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    I can no longer get it to build in VS with the following error

    cantbuild.JPG

    Digging deeper I think it is possibly:

    badRef.JPG
    Since as someone points out on SO:

    "Man I just wasted an hour on this. Thanks for the answer. The dll newtonsoft labels as being for 3.5 is actually not going to work with 3.5. You have to use the dll they label as being for .net 2.0. – Charlie Flowers Oct 15 '10 at 7:07"

    for the reasons explained here:

    http://devhawk.net/2008/10/21/the-fifth-assembly/

    Which is also expanded on http://stackoverflow.com/questions/11025100/escape-catch-22-with-extension-attributes-in-net-2-0 and http://devhawk.net/2012/06/20/ambiguous-extensionattribute-errors/ and other places.

    Is this a known issue. Gah. Will keep digging. :( <-- Yes it is

    I bought the 100 CCU service fwiw.
     
    Last edited: Mar 1, 2015
  24. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Okay.

    I ripped out the photon networking and confirmed that this is indeed what is stopping my project from building.

    Please can I get a fixed version?

    The info you need is above, many thanks, I will forward this to your official support mail.
     
  25. D_Cergy

    D_Cergy

    Joined:
    Feb 18, 2015
    Posts:
    35
    Hi, I have a problem with room filter.
    I already set my filter on JoinOrCreateRoom.

    Code (csharp):
    1.  
    2. RoomOptions option = new RoomOptions();
    3. option.maxPlayers = 2;
    4. option.customRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "L", selectedLevel },{ "R", false } }; //R for Random, L for Level
    5. string[] roomPropsInLobby = { "L","R" };
    6. option.customRoomPropertiesForLobby = roomPropsInLobby;
    7. PhotonNetwork.JoinOrCreateRoom("UserInputedName",option,TypedLobby.Default);
    8.  
    The problem is when the user from different level trying to join with same name. It will join the room with the same name, even the "L" filter in the CustomRoomProperties is different. Is it the right behaviour of JoinOrCreateRoom?

    Interestingly, I used the JoinRandom with the "R" filter which is working properly to not join the user defined room from the JoinOrCreateRoom.
     
  26. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    In JoinOrCreateRoom call, options are for the room, in case it does not exist yet. Else these values are ignored. (quote from method doc)
    JoinRandom uses options provided to find matching room. And fails if match not fond.
    Note that JoinOrCreateRoom should never fail.
     
    D_Cergy likes this.
  27. doubstract

    doubstract

    Joined:
    May 1, 2014
    Posts:
    20
    Can not find the answer everywhere, so i will ask here. It is legal to make asset (complete project) using PUN and sell it on Asset Store?
     
  28. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    When is the next version of photon out? Unity 5 support and mobile optimization?
     
  29. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Also can someone help me with a issue I have, using Unity Photon Pun+ latest version.
    When on multi-player, the room creator can send chat messages for all to see, but when another player sends a message it is not visible to all? What am I doing wrong?
     
  30. EugeneCib

    EugeneCib

    Joined:
    Mar 16, 2015
    Posts:
    1
    Is it possible to limit object instatiation rights with PhotonNetwork.Instantiate or by network view manual allocation (PhotonNetwork.AllocateViewID()) only to Master Client?
    And i would like to know is it totally bad idead to make network view for projectiles. In my case, they are relatively rear (not gun fire), but more like in Dota when casting spells. Is it bad idea to use network view in this case, because it would be much esiear to track and sync custom projectile behavior.
     
  31. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Do not use a photonView unless :
    - the object is controlled by the user
    - the object moves randomly

    If you fire a projectile, either it will just move forward or follow the target. In that case, you just have to broadcast the "fire" and the "takeDamage" (or whatever) methods. If you synchronize your projectiles, your bandwidth will just be overflowed.
     
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    New PUN versions are available in the Asset Store (PUN Free and PUN Plus).
    We checked iOS 64bit support and starting with Unity 4.6.3p2, exports work fine. Thanks to the Unity Team!
    (As before, you need Unity Pro to export PUN Free to mobile.)

    v1.51 (17. March 2015)

    Updated: PUN+ with a new native socket lib for iOS 32bit and 64bit. Please note: You need Unity 4.6.3p2 (or newer) to successfully export PUN+ to iOS! Before that "Patch 2" release, the new export did not work with PUN+.
    Fixed: PhotonAnimatorViewEditor for compatibility with Unity 5. Now Layers and Parameters can be configured as expected.
    Changed: A PhotonView that is created manually (by AddComponent()) will not attempt to register itself with PUN's internal list. Its viewID is 0. When you assign an ID to photonView.viewID, then it will register itself and can be found in PhotonView.Find(id). Make sure your IDs don't clash with IDs used in PhotonViews in the scene (1..999). Best, use PhotonView.AllocateViewID().
    Removed: A debug log in PhotonNetwork.networkingPeer.RegisterPhotonView(view) when you attempt to re-register a PhotonView and it's already in the list. This special case does not need logging.
    Updated: Several links to online docs, as the URLs changed. The basis is: http://doc.exitgames.com/en/pun
    Updated: Doc of PhotonNetwork.RaiseEvent. The EventCallback description here was wrong. In the callback you get the ID of the PhotonPlayer who raised the event. It might be 0 for "done on behalf of the room".
    Fixed: OnPhotonCreateRoomFailed gets the 2 extra parameters (return code and message) in all cases now.
    Added: Initial implementation of "CAS for Properties". This allows "Check And Swap" for SetCustomProperties. This should be a nice tool when any client can change a value and you want to make sure only one will succeed (can be picking up a item, making a kill, etc).
     
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
  34. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @doubstract: I don't know if the Unity Asset Store license covers this case but if you get in touch by mail and tell us a bit about your idea, we can surely find a solution and give you some other license. Mail to: developer@exitgames.com
     
  35. Deleted User

    Deleted User

    Guest

    Hi Tobiass, I'm getting a lot of errors with the new Photon release (this are not all of them, but all of the errors I'm getting come from LoadbalancingPeer).

     
  36. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @supremegrandruler: I have no clue how that happened. I assume it's a import issue or sorts.
    Please import the PUN package to a new, empty project and try to build a standalone. Then export the demos to your platform of choice. If it fails in either step, let me know which Unity version you use exactly.
    To fix any import issues, you can try to import again or copy the PUN files from an otherwise empty project over to yours via explorer/finder.
     
  37. Deleted User

    Deleted User

    Guest

    When I import PUN+, I skip the demo. Could that be why?
     
  38. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Skipping the Demo folder should not have any affect on PUN.
     
  39. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    Why do i receive this error when i start a fresh project of Unity4.6
    Import Photon only

    start demo scene i get those error :

    Code (CSharp):
    1. Receive issue. State: Connected Exception: System.Net.Sockets.SocketException: Une connexion existante a dû être fermée par l’hôte distant.
    2. -> An existing connection was closed by the Be the remote host
    3.  
    4.   at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x00000] in <filename unknown>:0
    5.   at ExitGames.Client.Photon.SocketUdp.ReceiveLoop () [0x00000] in <filename unknown>:0
    6. UnityEngine.Debug:LogError(Object)
    7. PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:160)
    8. NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1015)
    9. ExitGames.Client.Photon.<>c__DisplayClass2:<EnqueueDebugReturn>b__0()
    10. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    11. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    12. PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)
    and

    Code (CSharp):
    1. Cause: InternalReceiveException
    2. UnityEngine.Debug:LogError(Object)
    3. ConnectAndJoinRandom:OnFailedToConnectToPhoton(DisconnectCause) (at Assets/Photon Unity Networking/UtilityScripts/ConnectAndJoinRandom.cs:54)
    4. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
    5. NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1955)
    6. NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1582)
    7. ExitGames.Client.Photon.<>c__DisplayClass6:<EnqueueStatusCallback>b__4()
    8. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    9. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    10. PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)
    11.  

    Can i get some help plz i wanna try to understand the demo that come with the package
     
  40. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
  41. KeviN8543

    KeviN8543

    Joined:
    Nov 19, 2014
    Posts:
    6
    Can I develop with Photon on Macs or does it support Windows only?
     
  42. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    PUN can be developed on any platform that runs the Unity Editor and Mono Develop.
    The Photon Server only runs on Windows machines and it's strongly suggested to use Visual Studio for development.
     
  43. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    Hi,

    I use ConnectUsingSettings

    PhotonNetwork.ConnectUsingSettings("0.1");

    that call method " OnConnectedToPhoton " and "OnJoinedLobby" and everything work.


    My question is about ConnectToBestCloudServer

    PhotonNetwork.ConnectToBestCloudServer("0.1");
    Why ConnectToBestCloudServer doesn't work like ConnectUsingSettings ?

    That doesn't call any fonction and I got this message on console :

    Server to connect to: ns.exitgamescloud.com:5058 settings protocol: Udp
     
  44. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Maybe your network blocks using port 5058? The NameServer has it's own port number. Usually ports are not blocked though, because the client initiates the connection and can get replies...
    Do you have this issue in the Editor? Did you recently update to PUN 1.51?
     
  45. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    How can I block the PUN wizard when I don't want to use the Cloud services?
     
  46. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Hey. I had a few questions about the max messages and how exactly messages work. I am the lead programmer for a shooter called Warland and we are using Photon cloud. We have the package that allows 500 players connected and 500 messages per second in each room. According to your stats we have been going over 500 messages on average, often above 600.

    I'm a bit confused cause I added up the total sends each player sends and with everything added up it never goes over 14 sends a second per player (Which is 140 sends with our current max player count of 10). My question is, how can we be that high in messages? I feel like I was pretty careful in making it as efficient as possible, am I missing something? PS, we are mostly using RPC calls.

    Edit: Is there a way to accurately measure the exact amount of 'messages' per second in use with debug?
     
  47. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    I got this one hehe!
    10 players sending 14 messages is not 140 messages per second, because each message one player sends needs to go to the server and from there to all other players. So actually each player uses 140 messages per second.

    As you can see then it kinda stacks up with every extra player.

    Examples:

    3 players send 20 messages per second = 3x60 = 180.
    5 players send 20 messages per second = 5x100 = 500.
    10 players send 20 messages per second = 10x200 = 2000.

    Its one of the real limits of PUN, and therefore you need very decent inter/extrapolation or cut your numbers.

    For our game we set the limit at 4 players for this reason, because we wanted a lot of messages per second based on our fast paced gameplay.

    However PUN is still very cheap, because if you have enough players the amount of data you have to pay for can be huge with your own servers!
     
  48. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    I figured that.. So you're saying a sendrate of 12(Most of data is sent in one RPC at a sendrate of 12) is high? For a shooter?? Games like BF 1942 had up to 64 players 10 years ago and there is no way their sendrate was below 10, AND games were hosted by normal players with normal internet(Internet being terrible back then).

    Edit: Is there any way to customize a package with photon? Like have it memory based instead of 'message' based? Cause I could easily throw all data into a single bit array and use some compression techniques and get it down to a very small amount of data. I think the packages should be memory based and not 'message' based, it would encourage efficiency. :)

    Edit2: I just had windows monitor the amount received in the full game. It peaked at 6KBs. So I know that means that in the peak the server had to send 60KBs total. I would say that's pretty acceptable for a fast paced modern shooter with 10 players. Am I wrong?
     
    Last edited: Apr 8, 2015
  49. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You just have to be smart about your solutions. Like there are no reason to send a lot of messages to people far away. Players really far away could be updated 1 time per second, players a bit closer to you 5.... and so on. Network culling :D

    I know a lot of games can have a lot of players. But when i played things like BF 1942, it did work smooth untill to much action was going on in the same area and then they had the same problem.
     
  50. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    PS I added more to my previous comment. Well I have considered all these things but I really didn't think they were necessary for a fast paced close range shooter. Like 10 players is really low for a shooter and 60KBs should not be too much for photon(If it was memory based I could easily cut the memory usage in half but I have no motivation there).