Photon Unity Networking

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

  1. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    will you provide something like stardust for load testing projects made with new plugin?
  2. phil_ivey

    phil_ivey

    New Member

    Joined:
    Dec 3, 2010
    Messages:
    31
    Internal compiler error. See the console log for more information. output was:
    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

    right after importing downloaded plugin into clean new project. unity pro 3.4 win7 64 bit
  3. tobiass

    tobiass

    Member

    Joined:
    Apr 7, 2009
    Messages:
    826
    gnoblin:
    The Stardust tool is just a low-overhead application that uses multiple peers to simulate players. It's relatively basic and does not "understand" what Unity Networking does. And of course, it doesn't understand *your* game. So when you need load tests for your game, you need to implement them.

    phil_ivey:
    We also use Win7, 64bit Unity Pro and I think I never had this issue. Unity uses it's own compiler, so this won't be dependent on anything else installed. Maybe the 64bit hotfix Unity warns you about in the console (on startup)?
    It could be a "hiccup" in Unity. Did you try it again?

    Just in case it didn't happen when you import but after you unzipped the server: Please make sure you didn't extract the server's zip into the Asset folder. Unity will try to load assemblies which are meant just for the server. This is not a problem on import of the package from asset store though.
    Last edited: Aug 30, 2011
  4. NOVASOFTproductions

    NOVASOFTproductions

    New Member

    Joined:
    Aug 26, 2011
    Messages:
    132
    Plugin? Damn -.-

    I need to come into £1000 for Unity Pro :(
  5. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    No, I believe you can use this package/plugin in Unity Indie as well.
  6. Kaiserludi

    Kaiserludi

    Member

    Joined:
    Jan 21, 2009
    Messages:
    72
    Correct: Pro version is needed for native plugins (C, C++, objective C, etc.). .NET plugins can also be used with the indie version. Otherwise you would not be able to use Photon in Unity at all, not only this plugin, as it the classic approach is also a .dll.
  7. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    as per configuration yes
    and in the 0.93 Server (which was the asme but only 1 instance of game, not 2) it also all worked fine.
    I went through all configurations of the two and can't find any differences anymore as far as I'm aware so from my PoV it should work.

    the only delta the 0.93 and 1.0 server have is that the 0.93 32bit was the real one (for modern, real Windows systems, not for XP), while 1.0 has the _xp incaranation included unhappily likely cause thats the min requirement of unity itself.
  8. tobiass

    tobiass

    Member

    Joined:
    Apr 7, 2009
    Messages:
    826
    I don't know what's the issue with the policy request but we submitted a 1.1 update to the store.
    We fixed the XP issue where "access denied" keeps you from starting Photon. Also, Leepo found a few bugs in the management scripts, which you didn't find so far. Check out the release notes on 1.1 when it's up.

    By the way: We're using the XP 32bit server in the package, because that's most compatible. We decided against including other binaries due to complexity for new users ("which file should I run where?!"). Once the starting issues are resolved, this won't matter a lot.
  9. tobiass

    tobiass

    Member

    Joined:
    Apr 7, 2009
    Messages:
    826
    v1.1 is in the Store. Updated the original post.
    XP users should now be able to start the packaged server as expected. Make sure you have DotNet 3.5 (or up) and XP SP3 and up.
  10. rmele09

    rmele09

    Member

    Joined:
    Nov 8, 2010
    Messages:
    504
    Do you need to know how to program to follow this guide?
  11. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    Not more than knowing how to work with Unity Networking.
    But some basic programming is required if you want to syncronize more than transforms and rigidbodies yes
  12. phil_ivey

    phil_ivey

    New Member

    Joined:
    Dec 3, 2010
    Messages:
    31
  13. bertelmonster2k

    bertelmonster2k

    New Member

    Joined:
    Apr 3, 2009
    Messages:
    72
    Even with zoom I can't see anything in your screenshot.

    Just to be sure:
    The "Photon Unity Networking" Asset from the Unity Asset store is self-contained. It contains a small binary Photon Server (~4MB) and a 20CCU free license. This license does not connect to our license server.
  14. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    I've solved my problem by uninstalling .net framework 4.0, and installing .net framework 3.5.1
    Last edited: Sep 6, 2011
  15. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Where exactly?
    Sorry, I can't find it :confused:.
  16. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    Photon-Server\LoadBalancing\GameServer1\bin\Photon.LoadBalancing.dll
    Photon-Server\LoadBalancing\GameServer2\bin\Photon.LoadBalancing.dll

    Correct the "PublicIPAddress" value for both files.
  17. jaybones_old

    jaybones_old

    New Member

    Joined:
    Mar 31, 2010
    Messages:
    21
    Thanks, that solved my problem.
    both gameserver were set to 127.0.0.1
    instead my local. now all my clients on my lan can connect.
    Now its time to add features :)
  18. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Here's what I get in GameServers' log:

    I start LoadBalance as a service in PhotonControl.

    What does this log mean? (good\bad?)

    thanks,
    Slav
  19. bertelmonster2k

    bertelmonster2k

    New Member

    Joined:
    Apr 3, 2009
    Messages:
    72
    Please send me the complete log >> developer@exitgames.com.
  20. ExitBG

    ExitBG

    Guest

    Joined:
    Oct 16, 2009
    Messages:
    52
    This means that latency monitor was not able to connect to itself:
    The latency monitor is a connection to the game server to test the time it needs to process operations.

    The line below is actually a bug:
    The game server thinks he cannot connect to the master, but in truth this is due to a missing "return;" after the previous log output. You can fix this bug by inserting the missing line at LoadBalancing.GameServer.GameApplication line 206:
    Code (csharp):
    1.  
    2.  protected override void OnServerConnectionFailed(int errorCode, string errorMessage, object state)
    3.  {
    4.        if (state is WorkloadController)
    5.        {
    6.             log.ErrorFormat("Latency monitor connection failed with err {0}: {1}", errorCode, errorMessage);
    7.  
    8.              // latency monitor
    9.              ((WorkloadController)state).OnLatencyMonitorConnectFailed();
    10.              [COLOR="red"][SIZE="5"][B]return;[/B][/SIZE][/COLOR]
    11.         }
    12.  
    13.  
    This shows that everything went well in the end:
  21. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Is there any performance penalty for using Unity-plugin if compared to using Photon operations\events?
  22. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    Not really no, PUN (the unity plugin) is just a implementation of Photon in Unity and is using the "raw" Photon ops/events. PUN is not inefficient. Besides, you can extend it/cut it/optimize it. Furthermore both PUN and photon are maintained and optimized where possible.
  23. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
  24. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    I'm in the process of changing "int to short" as specified in PDF doc.
    This line confuses me a little:
    PhotonViewID[] viewIDs = (PhotonViewID[])evData[(byte)4];//LIMITS NETWORKVIEWS&PLAYERS

    do I need to fix anything here?

    thanks,
    Slav
  25. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,428
    Wow, this is pretty awesome news. I've been waiting and waiting with moving from Unity Networking to Photon (and it really kind of scared me ;-) ) - and now it's become so much easier. Downloading right now, looking forwarding to putting Traces of Illumination on Photon with Unity ;-)
  26. ccase

    ccase

    New Member

    Joined:
    Sep 10, 2011
    Messages:
    10
    Hey there,
    I researched quite a bit about the AI topic... If you want AI bots there are most likely three solutions...
    First..

    External Master Client
    You write the code of them in unity3d and let them run on one of the clients, maybe the masterclient.

    Pro
    - Its easy that way
    Contra
    - It cost more bandwidth and time (because the client must send extra data to the server)
    - The Client can abuse the data he sends
    - you have to save a copy of all bots on the server in the case that AI client leafs.

    Internal Master Client
    You start for each match a unity3d client on your server that manages your bots
    Pro
    - Its the second easiest way!
    Contra
    - Needs more server resources
    - Still is not that optimized as you still send datas between your masterclient and photon server

    Write Al logic and bots on your Photon server

    Pro
    - Its the most optimized solution
    Contra
    - You lose literally everything you have with Unity
    - No Unity Pathfinding (2.5)
    - No helper function you got from unity like for raytracing ect.
    - Well.. its not easy at all


    Can someone comment this? AI is a big topic and I think its hard to integrate, I would really love to hear a comment on pathfinding and approaches to solve such problems.
    Last edited: Sep 10, 2011
  27. ExitBG

    ExitBG

    Guest

    Joined:
    Oct 16, 2009
    Messages:
    52
    if you want to use shorts instead of ints for PhotonViewIDs modify the serialization in CustomTypes.SerializePhotonViewID/DeserializePhotonViewID.
  28. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    If I understand it correctly,
    RPC names are sent every time as strings (am I wrong?).
    Last edited: Sep 13, 2011
  29. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    Ah yep you're right, RPC names are send as strings.
    On the same note, networkviews are referenced by INT..this could be optimized to shorts to save data.
  30. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    What would you propose for optimization?
    It would be nice to send byte codes for RPCs instead of strings!
  31. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    As the full source code is available, you can fully optimize this to your needs. Of course bytes is most optimized..however I would go for usability and a bit less performance myself (and keep using String).

    Maybe its possible to generate a list of RPC functions/scripts and convert these to a bytecode? That could be an editorscript.
  32. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    or keep a Dictionary<string, byte> for these purposes
  33. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Isn't NetworkingPeer.monoRPCMethodsCache used for such optimization (already)?
  34. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    No, it only caches the local reflection results. So it remembers where to apply a certain method (string to method).
  35. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    I ended up creating
    and sending it as a parameter to RPC instead of string (also helps to see all used rpc "names" in one place).

    To execute RPC I convert it to string.

    *happyness*

    Open architecture of Photon is a very nice thing :).
  36. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    If I put loadbalanced game servers on different machines and those machines have different performance - how will Master split players over them?

    Will a powerful machine get the same amount of players as a not-so-powerful one? (sorry if I missed that in the docs)
  37. ExitBG

    ExitBG

    Guest

    Joined:
    Oct 16, 2009
    Messages:
    52
    the current version will distribute them evenly - but this behavior is meant just for testing.
    To distribute them depending on available resources change line 134 of file IncomingGameServerPeer.cs: In method HandleUpdateGameServerEvent call "TryUpdateServer" with "this.loadLevel" instead of "this.peerCount".
    This will push new peers to the server with the lowest load instead of the one with the fewest peers.
  38. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    I'm trying to add a buffered rpc to PUN example from asset store:


    And I get
    Although there's a second player with such viewID.

    thanks,
    Slav
    Last edited: Sep 15, 2011
  39. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Any hints on how do add a buffered rpc call that every new player who enters the game will get?
    I tried again with a freshly created project with a package from asset store (with no modifications) - but it still doesn't work :).
  40. the_gnoblin

    the_gnoblin

    New Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Oh, sorry!

    That was probably just an incorrect approach.

    I've solved my problem by sending buffered RPC from GameManager which already exists in the scene.

    thank,
    Slav
  41. darky

    darky

    Member

    Joined:
    Dec 9, 2010
    Messages:
    120
    Sorry for being a complete idiot, but I'm just starting with Networking. How exactly does Photon's CCU limit work? I'm working on a small FPS and now I am confused about how Photon works with the CCU limit and hosting in general.

    The normal work way is if I'm not mistaken: Post Server Info to Master Server (Unity Masterserver, PHP+MySQL, whatever) and Clients fetch the list and they connect to your hosted server. As many clients as the host defined or you as dev hardcoded can connect.

    Now with Photon how does it work with the hosting and the CCU? In my game, players would need to be able to open up their own servers and host for the other players. They could also use LAN. These servers are hosted via using Photon, if I am not mistaken. Does that mean the CCU limit is per server?

    Or does it work entirely different and it hosts EVERYTHING (even Players own "servers" or rather lobbies) and that way you can have only 100 CCU? In that case Photon wouldn't be usable for me. If this is the case, can someone recommend me what other Unity Networking Alternatives there are for my use-case (preferably comparable to Photon's stability)?

    I hope to receive some clarification soon :)
    Thanks!
  42. fholm

    fholm

    Member

    Joined:
    Aug 20, 2011
    Messages:
    1,626
    Darky, if your players are going to host their own servers (like counter-strike, quake, etc.) I would recommend going with the built in unity networking.
  43. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    Photon CCU works per server. So the default free license allows 100 players to connect to your Photon server and start/join rooms there..there are no room limits, so any combination of rooms is possible. The photon server acts as masterserver as well.

    If costs are a big issue AND you need more then 100 players online at the same time then you can use Unity networking for now.
  44. darky

    darky

    Member

    Joined:
    Dec 9, 2010
    Messages:
    120
    Ok, got it. Thanks for clarification, then it'll be normal Unity Networking for me.

    Still, great work on Photon. I wish you the best of success with it, I'm sure its great :)
  45. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,428
    I'm still new to Photon, so I might be missing the obvious - but where can I find the full source code? I see Plugins/PhotonNetwork with a couple of classes and a library (Photon3Unity3D). How can I build that library? How could I debug it?

    My problem is that I'm currently running into an issue with "Connection refused" somewhere in the depth of ExitGames.Client.Photon.NConnect.SendUdpPackage and being able to look what exactly is going on there would probably help.

    But I've also posted a question on this in the ExitGames forum: DemoWorker can only connect locally

    EDIT: Well ... looks like I looked into the wrong configuration files ... I did remember there was something in the manual:

    (from 2.1 Server deployment)
    Last edited: Sep 16, 2011
  46. jashan

    jashan

    Member

    Joined:
    Mar 9, 2007
    Messages:
    2,428
    Today, I tried converting my project ... and things looked pretty okay in the beginning. But after a while I found out that the converter broke a significant amount of my prefabs (probably that was done by adding the PhotonView component). I'm afraid I'll have to revert that conversion. Maybe I can come up with an easy fix by just reverting the scene files. I'd have to do a *lot* of manual, boring and error-prone work to fix all my levels when all the prefab connections are broken (I have one power-up prefab and a setting for the type of power-up; so when I do revert, I have to recover that setting).

    I'll have to see - maybe I can fix the converter to check if an object has a prefab, and if so, ignore it in the scene (would be sufficient to just fix the prefabs in the project and leave the scene instances alone). Not sure if the editor API provides a way to check that, though ... and if not ... hm ... that would suck.

    In that context, I also noticed that the converter seems to leave the NetworkView components in place. Is there a reason for that? It seems to me that those would just bloat things but maybe I'm missing something.
  47. moo

    moo

    New Member

    Joined:
    Sep 10, 2011
    Messages:
    2
    Thanks so much for the great work! This plugin works great for me.

    Will the source code ever be available? If so, any idea when?

    Being able to add functionality on top of this already great plugin would be very very helpful!

    Again thanks for all of your efforts!
  48. syrka

    syrka

    New Member

    Joined:
    May 20, 2009
    Messages:
    14
    another little question: how do i call a custom operation at the photonserver? Is that supported by the addon?
  49. MikeHergaarden

    MikeHergaarden

    Member

    Joined:
    Mar 9, 2008
    Messages:
    885
    jashan:
    Ah I think we chould move the prefab conversion BEFORE the scene conversion to easily address that?
  50. mrde

    mrde

    New Member

    Joined:
    Jan 13, 2011
    Messages:
    8
    Hi all.
    I look the viking demo video http://youtu.be/f8S-xSsB9hg

    // code
    if (!PhotonNetwork.connected){
    PhotonNetwork.Connect("127.0.0.1", 5055, "MyVikingGame");
    }

    Why in this youtube video there is nothing about MyVikingGame server application?
    Where is it???