Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon Unity Networking

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

  1. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Yeah, I think that should solve it. When you do the prefabs first, when you open the scenes afterwards, any prefab-based objects should already have a PhotonView and you might just need to update its properties (which shouldn't break the prefab connection). Sounds like a good solution to me :)
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    Update:
    The current setup will more or less ignore this value. Any name you offer will be mapped to the LoadBalancing application, if you run the included server.
    So you need to run a Photon MasterServer per game (example: one for chess and one for your FPS).

    Otherwise you have to separate the lobbies, players, user-counts. Anything that belongs to one game but not the other. So it's way simpler to run just one game per Photon instance.
    Our upcoming hosted solution will use this string to define which game the client actually refers to. But that's another story ;)

    In both cases, just one "general" server side logic is running.
     
    Last edited: Sep 19, 2011
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Ratz: Where's my head been? I missed this! If it weren't for the Photon Network Engine News eMail, I've missed it completely.
     
  4. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Edit: Oops, answered wrong question.
     
    Last edited: Sep 19, 2011
  5. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Big thank you to everyone involved into creating the plugin!! :)
     
  6. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Awesomeness! I have Traces of Illumination running with Photon - yeeha!

    I had to rewrite parts of the plugin and it's really just "prototype-style" right now with quite a bit of stuttering and probably multiple simultaneous game sessions not really working (and my load-testers and logging not working either because they rely on having IP-addresses) ... but I've got the level prefixes acting properly, which was the greatest issue for me for now, so that's really really cool!

    I actually planned moving over to Photon much later but with the plugin, it was just too tempting to not try it now ;-)

    So far, it took me about 17 hours - and that includes rewriting PhotonViewID to have prefix as byte, id as short and actorID as short (and introducing and fixing one very nasty bug when first trying to use ushort instead of short ;-) ). @Leepo: Can I send you those changes? I'm not expecting you to integrate all - or even any - of them but in case you would, I wouldn't mind ;-)

    Next step is cleaning things up and checking everything in after careful review of the changes ... and then I'll have to tear the Loadbalancer app to pieces and put it back together with scope based on teams, game groups and "server" (the rooms concept really doesn't help me at all - currently, I'm simply putting everything into one room). That step will also include re-introducing playerIPs (I need those, at least on the Unity game server aka "MasterClient"), making sure my game server always is my MasterClient; moving significant parts of the logic from my Unity game server to the Photon server ... and finally the possibility to connect multiple Unity game servers to the Photon server for load balancing (each Unity game server can handle a few game groups which are "kind of like rooms").

    Ah: And I'll make sure to replace the RPC-strings with short IDs (I already have a couple of ideas of how to implement that and it should be pretty convenient in the end - working with strings which aren't checked by the compiler has been bothering me ever since I started using Unity's networking ... it kind of feels like browser-JavaScript ... meh, need intellisense plz ;-) ).


    When all of that is done, it would be great if I could get some help with load-testing that thing. My last load-test was about 3 years ago and it revealed that with Unity's networking, I'm hitting a pretty unpleasant limit with 80 players per Unity game server (I'm not saying that was Unity's networking fault - I guess it was more just me using it for something it was never really designed for ;-) ). It'll be exciting to see how many players (or simulated players ;-) ) I can get onto the Photon based approach. I also did quite a bit of optimization in the server ... and moving logic out of Unity into Photon should also help ;-)
     
    Last edited: Sep 20, 2011
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    Jashan: Great to read you got your game basically running with the plugin now!

    It's kind of funny that you dislike the RPCs with string identifiers, because we use byte-codes for operations and events throughout Photon but implemented Unity's RPC workflow especially for this plugin.

    Of course we would like to take a look at your modifications.
    At the moment we're preparing ourselves for the Unite 11 but after that we will take a look at all the feedback and suggestions and update the plugin as soon as possible.
     
  8. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    It's even more funny because having to create operations for all my RPCs was really the thing that scared me most when considering porting to Photon ... but I think now I can create an app for that ;-)

    The greatest thing for me about PUN so far is that it gives me a way to iteratively port my project: I had my first successful little test-session after about 6 or 7 hours of "porting" (and that included quite a bit of learning about Photon). Then I ported the PhotonViewIDs to properly support level prefixes and did some optimizations (going from int to byte for prefixes and from a single int to two shorts for viewID and owner/actor-id). After that, I could playtest again (and easily discover, for instance, that I missed a null-check on the owner when serializing PhotonViewIDs).

    This way I can take one step at a time with a more or less working project after each step - which makes the whole process much less daunting. And what I love most about this: Where Unity's networking was an immutable blackbox, I can simply twist and tweak Photon until it does exactly what I want it to. Like: I have messages that need to go to all players currently on the (Photon) server. I also have messages that need to go to all members of the game group the player is currently in. Then, I have messages that only go to those players of a game group currently playing in a level (only those that were in a team when the current session started). I also got messages that only go to the player's team, and messages that go to specific other players, or to the "server" (a Unity game server).

    Once I have all those entities represented inside Photon, it should be fairly easy to extend PhotonTargets (or what it was called) with those targets and make sure everyone only gets what they need (I did have this in Unity networking, too - but it was a really cumbersome approach until they added SetSendingEnabled per player - and given that this is based on groups of which there only are 32, it's still not really an approach I'm particularly happy with) ;-)
     
  9. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    Hey,
    I followed this tutorial http://www.youtube.com/watch?v=f8S-xSsB9hg&feature=youtu.be but all i get when i start the game is a grey screen, no error messages. I checked if everything is correct but found no mistakes in my scripts.
    Does somebody know what the problem could be :)?

    EDIT: Just found it out on myself. I wrote OnGui instead of OnGUI ;)
     
    Last edited: Sep 21, 2011
  10. evillemez

    evillemez

    Joined:
    Sep 21, 2011
    Posts:
    24
    First off, HUGE thanks to Leepo and TobiasS for this plugin. I've been very apprehensive about diving into a 3rd party networking solution until I read about this plugin.

    Question:
    How realistic would it be to implement networking in code such that the player would have the option to host their own smaller game using the Unity built-in networking, AND have the option of joining/starting a game on a dedicated server being powered with Photon?

    Up till now I figured I would just design my game using built-in... then go through lots of pain once I hit the limits of the built-in networking, and port over to Photon or some other solution. But, seeing that these have similar APIs and there is the free 100CCU testing license, it now seems reasonable that I could design with both in mind.

    From your perspective(s), is it reasonable to expect to be able to do this? Or is there an obvious gotcha that would prevent being able to support both?
     
  11. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    I'm sending RPCName.SendChatMessage instead of "SendChatMessage"

    where RPCName is

    I had to modify 3 RPC() methods and ExecuteRPC() method in the code of plugin in order for this to work.

    I'm quite happy with the solution, hope this helps!

    thanks,
    Slav
     
  12. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Before PUN I didn't personally realise that Unity probably sends rpc names as string every time :).
     
  13. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    It's sure possible; you could keep PhotonViews and NetworkViews both in place and have some sort of NetworkManager in which you can switch which approach is used. But the question is: What would be the real benefit? It'll add quite a bit of complexity to your project (and networking is already a complex beast without supporting two different networking layers).
     
  14. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    I don't think it does. I'm pretty sure they dynamically move the strings into some sort of dictionary and when you call an RPC, look up the code for the procedure call, send the code over the network and resolve it back on the other end. Usually, you do count each byte in your networking protocol, so sending method names over the wire is fine for a prototype but certainly not something you'd want to do in a production system.
     
  15. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    What I'll probably do is have a separate enumeration for each object that has RPCs. That'll also give me the benefit of having all this information in one single file that I can easily generate by having an editor script run through the code. But this sounds like a good starting point, and it's good to know that it's really only 2 places that you need to change (I count the different versions of RPC as "one place") and nothing "big" in the core of things ;-)
     
  16. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
  17. evillemez

    evillemez

    Joined:
    Sep 21, 2011
    Posts:
    24
    Thanks for the reply.

    The benefit would be allowing players to host their own smaller games, on a LAN for example. But also have the ability to join larger games on dedicated servers. I hope to be able to do up to 32v32 in the sim I'm about to start work on. If I can push past that, I'll be very happy, but it's not a requirement. But, I would like people to be able to host their own private 3v3, or 4v4 type games if possible.

    I figure that if it's possible abstract out the specific network backend, then it may be easier to implement other networking backends down the road by providing adaptors for translating to that backend. I'm not totally convinced yet that it's worth the work, but if it were the kind of thing the community seemed interested in, I wouldn't mind exploring the idea further.
     
  18. rhamm1320

    rhamm1320

    Joined:
    Mar 29, 2008
    Posts:
    44
    I can see an advantage too to both ways. If you can keep the server traffic down with direct connections and use the server with Photon for tournaments etc, but 1 vs 1 play use direct connections and only use the server for matchmaking
     
  19. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Ok, probably you're right :).
     
  20. evillemez

    evillemez

    Joined:
    Sep 21, 2011
    Posts:
    24
    On thinking more about this, and looking into the PUN code in greater detail, I realize how complex it would be to abstract the network backend - but also it occurs to me that it may be a moot point.

    As I understand it, anyone can download and use the 20CCU license server... so, is there any technical/legal/licensing reason why people could not just download the Photon server to use on their LAN for 20 persons (or fewer) games, if they really wanted to host something locally?

    If this is indeed the case, that would pretty much solidify my decision to ditch built-in networking and just go with Photon, as the only reason I wanted to potentially support both was to not completely lose the ability to host your own games for smaller numbers.
     
  21. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Actually, I had an idea today that might make this much easier than I originally thought. You might get away with just having two different ways of connecting to the servers (that's where the approaches are really really different) and then only use PUN ... but: In the RPC() methods, you might add a switch that sends messages via Unity networking on demand, instead of using Photon. That might be a fun experiment and should also be interesting to be able to do direct product to product comparisons (like performance). Just make sure PUN doesn't remove any of your NetworkViews ;-)

    One thing that I had been planning to do is add options for other network layers like something that uses Bluetooth on mobile devices, or some of the other networking options built into those devices. As we have the source code of PUN, this should be possible ... and on mobile devices, I see quite a benefit of having something like that available (people might not have a great Internet connection but could still play with a local ad hoc network).
     
  22. evillemez

    evillemez

    Joined:
    Sep 21, 2011
    Posts:
    24
    Hmm... that's an interesting idea. When I get back to working on the networking aspect of my game, I'll look into that and post back if I make any progress. I probably won't get back to it for another two weeks or so, unfortunately.
     
  23. mrde

    mrde

    Joined:
    Jan 13, 2011
    Posts:
    8
    Thanks for answer. I understan my problem.
     
  24. mrde

    mrde

    Joined:
    Jan 13, 2011
    Posts:
    8
    Hi.
    When i register custom types as Viking Demo in client and trying to send operation with this data to server, server disconnecting saying DisconnectByServerLogic.
    Maybe I must register custom types in server too ????
     
  25. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Is anyone else having trouble with the Exit Games forums? For me, for two or three days it takes forever to load the main page (and sometimes completely fails) - and I can't really enter any of the forums either.
     
  26. mrde

    mrde

    Joined:
    Jan 13, 2011
    Posts:
    8
    Yes It doesn't open. Fails on forum page.
     
  27. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Yeah, it doesn't load.
     
  28. bertelmonster2k

    bertelmonster2k

    Joined:
    Apr 3, 2009
    Posts:
    78
    In the works, sorry.
     
    Last edited: Sep 26, 2011
  29. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Good luck!
     
  30. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Ah - great to see the forum is back online again :)
     
  31. mrde

    mrde

    Joined:
    Jan 13, 2011
    Posts:
    8
    Resolved: Protocol.AllowRawCustomValues = true
     
  32. Crit

    Crit

    Joined:
    Jul 22, 2011
    Posts:
    15
    If I change the nickname I receive

    errors, any fix for that?
     
  33. wubj

    wubj

    Joined:
    Sep 29, 2011
    Posts:
    1
    After clients join the room,
    Did clients transfer data peer-to-peer with other clients in the same room?
    or need server to rely and broadcast the data in the same room?

    thanks,
    BJ
     
  34. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    There's no peer to peer with Photon (or Unity's built-in networking).
     
  35. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    I also have nickname error :).
     
  36. Crit

    Crit

    Joined:
    Jul 22, 2011
    Posts:
    15
    So the communication (ingame) is always:

    masterclient <-> Photon Server <-> other clients?
     
  37. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    Yes, this the norm for pretty much every network implementation around and 99% of all commercial games.
     
  38. Crit

    Crit

    Joined:
    Jul 22, 2011
    Posts:
    15
    Okay, that could be the reason why my multiplayer game is laggy with PUN, because I host my photon server on a pretty slow external connection currenty.

    Is there a option to allow a direct communication between the masterclient and the other players?
     
  39. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Unless you want to simulate worst case conditions, you should have Photon and your masterclient in the same local network, and it should be a fast connection. For development, having Photon on your local machine or in a virtual machine is probably best.

    AFAIK, there is no peer to peer in Photon, so no you can't directly connect client and game server. Theoretically, you could use Unity's networking for that but I wouldn't want to add that kind of complexity ;-)
     
  40. th.koder

    th.koder

    Joined:
    Jun 20, 2011
    Posts:
    5
    Hi,
    Will Photon work in case of client to server connection both having port restricted nat capabilities(returned by Network.TestConnection()) ?
    Unity seem to fail for this case and I wanted to know if you implemented this feature.

    I'm sorry if this already have been answered in this thread.
    Thanks!
     
  41. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    It's answered in the docs of PUN (Photon Unity Networking) ... or maybe even somewhere else. As Photon usually is running on a real server, you shouldn't have issues with NAT. If, however, you have your Photon server running at home with some funky DSL-connection for production use ... well, then you really shouldn't be doing multiplayer games ;-)

    If your client sits behind a firewall that doesn't let you connect on the relevant port(s) on the server ... then it also won't work, of course.
     
  42. th.koder

    th.koder

    Joined:
    Jun 20, 2011
    Posts:
    5
    Thanks, jashan. Will read docs.

    Photon does not support p2p:
    http://forum.exitgames.com/viewtopic.php?f=6&t=55
     
    Last edited: Oct 2, 2011
  43. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi guys, quick question ... if I'm trying to get into Photon Server, should I start with this package and try to disect the code to understand how it works or should I instead work with one of the examples like the Viking Demo?
     
  44. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    This demo and the Viking demo are similarly simple. Use either or better: both.
    Neither requires server programming but make use of a "MasterClient", which could be made authoritative to some degree.
     
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    We updated this package in the asset store as v1.2.
    It includes fixes to known issues and adds a setup wizard for our new Photon Cloud Service, which is in public beta currently.
    Alternatively, the v1.2 package is also compatible with our Server SDK RC4 (make sure to run the "Loadbalancing" setup).

    Check out the original post for updated info.
     
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    Good news, everyone: The new version just went live in the asset store!

    It fixes some issues (e.g. with masterClient and viewIDs), gets you a bit more performance (we're no longer using BroadcastMessage) and we tried to add the improvements everyone was submitting (better support for JS in the "Unity Networking to Photon Unity Networking" converter and PhotonNetwork.time is now more like you know it).

    I updated the first post with all details on v1.3 and they are also in the asset store.

    We're very proud that the first games are already live with Photon Unity Networking and the Photon Cloud as well.
    Thanks for the great interest, lots of feedback and cooperation on this :)
     
  47. EvilDingo

    EvilDingo

    Joined:
    May 7, 2011
    Posts:
    190
    No games are showing up.

    I've loaded the testGame scene. Changed the app ID to the one I got from the website.

    Ran the test. It appears to connect properly and I can create a room. If I run the test from another source (mobile, win client, etc) the room I created is not showing as an option. I can't join it.

    I can create a new room but these are all isolated.

    Any ideas? This seemed like a simple test to try. :)
     
  48. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,056
    EvilDingo:
    I assume you are trying the test in the "DemoWorker" folder? The weird thing is: for me it runs just fine.

    For some users, problems were resolved after deleting the package and re-importing everything from it.
    I think you already made sure but just to exclude everything: Please make sure you run the same build as standalone and in editor, after saving the appID and the PhotonServerSettings (with PhotonCloud selected).
    Otherwise, it could be a temporary issue with the server - then it could be solved by now.

    If none of this helps, please let me know and we get in contact more directly.
     
  49. EvilDingo

    EvilDingo

    Joined:
    May 7, 2011
    Posts:
    190
    Hi Tobias,

    I found a work around. In the initial set up, I set up my APP ID for the cloud based multiplayer. But no connecting clients can see the game. To fix it, I went into the Resources folder and set the PhotonServerSettings to SelfHosted but kept the URL and everything else the same.

    It works!

    Seeing the little Worker walking around (huge latency, but it's working -- must be a master server far from Australia) on my Android phone was cool. Removed WIFI access and tried on 3G -- still works (more latency though.) I'm planning on a lot of latency so that isn't putting me off. :)

    Cheers!
     
  50. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,089
    Is there any plans to extend the photon cloud to support authoritative architecture? Perhaps spawn a headless Unity MasterClient for every "room", or something?