Search Unity

New Photon Unity Networking Tutorial Series

Discussion in 'Connected Games' started by Oliver-Eberlei, Apr 17, 2014.

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    Gunhi: Which platform do you build for? This could be a problem with some platforms that are not yet fully supported by PUN.
     
  2. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    294
    I'm using PUN+ and target build is iOS
    Unity 4.5.1 on MAC

    Just simple import SKY project then PUN+

    All of them are the latest version.
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    I guess the import "failed" because the PUN+ source is older than the files in the Sky project. Some files are in both packages but slightly different inside.

    Backup your project first, then try this:
    Import PUN+ in a new, empty project.
    Close your existing project and copy the PUN+ files into it via Finder.
    Make sure to "merge" all folders into existing ones and to "overwrite" or "replace" anything existing related to PUN.
    You can skip the Demos and any *.meta file from the PUN+ folder.

    This usually fixes the issue. I will look into making this more seamless in the coming updates.
     
  4. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    294
    I did what you said. Just copy 2 folders "Photon Unity Networking" and "Plugins" rewrite to exits folders.
    then get these error from Sky scripts.

    ===
    Assets/Scripts/Chat/ChatHandler.cs(4,31): error CS0234: The type or namespace name `Chat' does not exist in the namespace `ExitGames.Client.Photon'. Are you missing an assembly reference?

    Assets/Scripts/Chat/ChatHandler.cs(12,43): error CS0246: The type or namespace name `IChatClientListener' could not be found. Are you missing a using directive or an assembly reference?
    ====
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    It seems you are now missing some files related to the chat api (for whatever reason). You could try to re-import everything chat related from the Sky Arena package. Any folder that's labelled Chat and any file that is.
    We are derailing this topic a bit. If you continue to have problems, we should continue in our Exit Games forum. Hope you are OK with that.
     
  6. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    294
  7. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Oliver, I have been looking through the scripts and have been trying to figure out how to add more than 2 maps. But I can't find it. Any help is appreciated. Thanks :)

    EDIT: Oops, sorry! I found it! :) its in the server options script...
     
    Last edited: Jul 17, 2014
    stvster likes this.
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    For your info:
    The current Sky Arena is not PUN+ compatible, due to the included Photon Chat features.
    We will update the Chat code soon. Until then, please don't try to import PUN+ for mobile...
     
  9. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    294
    How long does it take to get the update?

     
  10. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    I think I found a showstopper and it's more complicated than just setting a few values correctly.
    At the moment, I can't say when Chat becomes PUN+ compatible. I can only say we will work on it as one of the next tasks...
    Sorry for the bad news.
     
  11. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Im trying to set up a script that when i press the escape key (Using input.getbuttondown) and I'm calling this:

    Code (CSharp):
    1. PhotonNetwork.LeaveRoom();
    But in the MultiplayerConnector script, in the OnLeftRoom function (or void) it says that it will load the RoomBrowser scene. it does load that scene, but after a second or so, it will go back to the main menu. Is there a solution for this? Thanks.
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    Most likely there is a solution to this but I can't know it. Photon is not changing any menu states, so you have to carefully check your logic and callback methods and see if some gets triggered where you didn't expect it.
     
  13. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    Thats what I did.. Can't see anything though. Ill keep looking. Thanks anyways! :)
     
  14. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    73
    I have an odd problem. If I build for Mac OS X and I start a room I can connect to it using Matchmaking no problems. But if I go into the room browser and try to connect it just sits on the screen saying Joining Main Camera... Joined Lobby. I have uploaded a screen shot. Any ideas?

    Screen Shot 2014-07-18 at 1.28.07 PM.png
     
    Brendonm17 likes this.
  15. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Hi BurningThumb,
    Yea,this faked me out also at first.It's a Fake room as far as I can tell..
    Check around line 141 in RoomMenuRoomBrowser.cs.
    Look for Void CreateDummyRoomInfos().
    I'm trying to figure how to display active rooms in my particular game but not even sure this is possible at the moment.
    I suspect it is possible but I haven't solved the issue yet.
    Having a blast with this package none the less
    :D
     
    Brendonm17 likes this.
  16. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    73
    Hi stvster,

    Its not the fake rooms. I took those out first thing. Its an actual room with my application ID. As I said in my post if I use the matchmaking tab it connects just fine and I get 2 ships in the room on the network - very cool. Its only when I go to the rooms tab, I can see the room info so I know that part is working, I just can't connect to it. I'm going to look at the connection code today, I'm sure its an easy fix, I just was wondering if someone else had already solved it - but I guess not. If it turns out to require a code fix I'll post it when I find it.

    FYI, here is a screen shot of the room info just before I click it.

    Screen Shot 2014-07-19 at 11.56.01 AM.png
     
  17. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Thanx for the info BurningThumb.I could use some help on how you got your room to show in Room Browser.I'm glad you started this posting and appreciate any info you can pass along.
    Thanx!
     
  18. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    73
    Ok. Its a bug. The file name is RoomMenuRoomBrowser.cs and the method is at line 396 called DrawRoomListButton( floattop, RoomInforoomInfo ). The bug is lines 415 and 417, they reference name which is returning the gameObject name *not* the room name. You need to change those lines to reference roomInfo.name:

    Code (csharp):
    1.  
    2.   m_JoinRoomName = roomInfo.name;
    3.  
    4. PhotonNetwork.JoinRoom( roomInfo.name );
    5.  
     
    andrescavallin and stvster like this.
  19. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    73
    Did you setup your Photon App ID:
    Window > Photon Unity Networking
    Click the button called Setup
    Enter your Appid

    Then there is an if statement somewhere, I forget exactly where, that is looking to see if photon is connected. Because the if is commented out its always displaying the dummy rooms. I got rid of the if statement all together and just display the real rooms returned by photon.
     
  20. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    73
    I found it. This is the method that needs to be changed:
    Code (csharp):
    1.  
    2.   voidDrawRoomListButtons()
    3.  {
    4. if( m_IsJoiningRoom == true )
    5.  {
    6. return;
    7.  }
    8.  
    9. List<RoomInfo> roomInfoList = newList<RoomInfo>();
    10.  
    11. //Dependingonwhetherweareonlineoroffline, eitherdrawtheroomlist
    12. //wereceivefromPhoton, ordrawourowndummylist
    13. if( PhotonNetwork.connected == true )
    14.  {
    15. roomInfoList = newList<RoomInfo>( PhotonNetwork.GetRoomList() );
    16.  }
    17. else
    18.  {
    19. //roomInfoList = newList<RoomInfo>( m_TestDummyRoomInfos );
    20. roomInfoList = newList<RoomInfo>( );
    21.  }
    22.  
    23. //Sortthelistfirst
    24. SortRoomInfoList( refroomInfoList, m_SortRoomList );
    25.  
    26. //Andthendrawallthebuttons
    27. for( inti = 0; i < roomInfoList.Count; ++i )
    28.  {
    29. DrawRoomListButton( 94 + i * 50 + 50, roomInfoList[ i ] );
    30.  }
    31.  }
    32.  
     
    stvster likes this.
  21. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Hi BT,
    Thanx for the quick reply.My AppId is set and all is well net wise.The room browser fix is Greatly appreciated.I may be able to sleep better now:).Well done and Thanx again.
    EDIT:
    Works like a charm BurningThumb.I can see rooms AND join them!:D
    Brilliant solution you provided.
    THANX!
     
  22. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    Short heads up: Oliver is super busy organizing booths for some indies at Games Com next month.
    That's no excuse for not being responsive here but it explains things, I guess ;)
    I'll bug him to reply and will try to help tomorrow, if I can.
     
  23. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Hi tobiass and all,
    Nice to hear from ya.Things are running very smooth here and thanx to BurningThumb's input all features are working great.I hope Oliver has a good time at Games Com.He deserves it.Kudos to you also,tobiass.
     
  24. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Hi,
    I've added new maps which show up fine in the Map Queue but am having a problem creating a check box and Map name to the Add map to queue section.Any help is appreciated.Thanx!

    side note:
    I'm kinda surprised that this thread isn't more active (not complaining) and hope sales were good.I'm very glad to have this terrific asset.

    EDIT:Solved thanx to Brendonm17's earlier post.
     
    Last edited: Aug 22, 2014
    Brendonm17 likes this.
  25. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    I would like to to see series on the social part of multiplayer games.

    Friends list
    grouping
    secure trades
    ect..
     
  26. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,284
    do you plan to port it to the new GUI ?

    it would be great and also easy to port with ngui
     
  27. ravindraK

    ravindraK

    Joined:
    Jul 18, 2014
    Posts:
    5
    Hi Thanks for creating wonderful tutorials and i am looking forward to buy the source code from the asset store, but only have one query, you have mentioned in the description on asset store that not all code are included for download so i just want to know if you have included multiplayer UI and red team blue team selection part in the download bundle because that's the main part where i am stuck right now . Thanks
     
  28. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Hi ravindraK,
    The Sky Arena asset that I purchased from the asset store includes a fully functional multiplayer project.It also has an offline scene.Just add your Photon APPID and a chat id and should be good to go.I think they meant the "not all code" thing referred to the Full Sky Arena Game they posted for download to showcase what can be done with the Awesome Sky Arena asset .I've tested it with a player from Canada(I'm in US) and he had DIALUP! Still ran smooth.Totally worth the price.
    Thanx for reading this.
     
    ravindraK likes this.
  29. ravindraK

    ravindraK

    Joined:
    Jul 18, 2014
    Posts:
    5
    Thanks so much for your reply stvster, After your reply i bought the Sky Arena Project and yes it includes full multiplayer functionality.
    thanks
     
  30. Oliver-Eberlei

    Oliver-Eberlei

    Joined:
    Jun 12, 2011
    Posts:
    110
    Hi guys, I am back from my travels. So let's tackle your questions :)

    @Damien Delmarle: Not right now, sorry. The focus of this tutorial is multiplayer so updating to the new GUI wouldn't make any difference for the multiplayer part.

    @ravindraK: Yeah you're right, the description is a little bit weird. What I meant to convey is that this is a seperate project to my game Sky Arena that I am developing right now. I just used a few of the assets from Sky Arena for this tutorial. Since the game and the tutorial are both called Sky Arena, I wanted to make sure that people know that this is a seperate project. Everything you see in the web player demo is included in this package of course.

    Everyone else seems to have resolved there problems, right? Otherwise please write a short answer that you still need help and I will try my best to help you fix your issues.

    Cheers,
    Oliver
     
  31. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Welcome back Oliver,
    You wrote such a good program that no one seems to have any problems :)
    Well Done!
     
  32. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    67
    Your welcome ravindraK,
    I'm sure you'll enjoy it,
     
  33. EnigmaFactory

    EnigmaFactory

    Joined:
    Dec 10, 2011
    Posts:
    91
    Hey all! This is totally awesome. Thank you so much Oliver!

    So I'm adding a new ship mesh. The goal is to have modular ships so you can upgrade the fuselage, wings and propulsion systems independently. I've successfully modeled and imported a new base mesh for the ship. I've applied the normal skin to it so I can adhere to the same coloring system for team matches. My question is, how do I define what areas get the primary color vs the secondary color using this custom shader? When I apply it, it's all the secondary color using the skymap gradient. Thanks for any advice!
     
  34. Brendonm17

    Brendonm17

    Joined:
    Dec 9, 2013
    Posts:
    43
    In your modeling program select the faces you want to be the main color, and create a material for them (within your modeling program) with the same name as the main material in unity. select all the other faces, and create a second material (modeling program) with the same name as the second material in unity. apply both materials respectively. once your back in unity, the textures should be applied accordingly. if not, check your import settings.
     
  35. Keith90

    Keith90

    Joined:
    Sep 27, 2013
    Posts:
    116
    If I have never programmed online multiplayer before, how difficulty would it be for me to get Photon to run? My game is a 2D arena fighter, similar to Smash Bros in terms of movement. I hope it wouldn't require a lot to do so for a simple game.
     
  36. Oliver-Eberlei

    Oliver-Eberlei

    Joined:
    Jun 12, 2011
    Posts:
    110
    Hey @Keith90. A fighting game is a special kind of breed when it comes to online multiplayer since timing is so important and the characters have to react pretty much immediately when you hit your buttons. I havn't created a online fighting game myself yet but I imagine that you have to get quite creative to hide the fact that the data takes time to travel over the internet.

    Getting up to speed with Photon is very easy, but I would suggest making a smaller prototype first to learn Photon that is not a fighting game. A simple top down racer is way easier for example since you can follow the tips and tricks in my tutorial for prediction.

    @EnigmaFactory the shader uses vertex colors to determine between the primary and the secondary color. This is the line in the "enemies" shader that is relevant:

    Code (csharp):
    1. o.col = lerp( _Color, v.color * _Color1, v.color.a) ;
    _Color is the secondary color (I know the naming is weird, just go with it ;) ). This is the team color, red or blue in our case
    _Color1 is the primary color, basically the rest of the ship that is more grey-ish

    If the alpha value of a vertex is 0 then the team color is used, if the alpha value is 1 then the other color is used (multiplied by the RGB values of the vertex color to be able to have more color choices for the design of the ship if you need them)
     
  37. iCode

    iCode

    Joined:
    May 25, 2013
    Posts:
    32
    I just purchased this, and am excited to learn from it, however, I notice this package doesn't not use the latest Photon version. I was wondering if you have any plans to updated it and when that might be?
     
  38. Oliver-Eberlei

    Oliver-Eberlei

    Joined:
    Jun 12, 2011
    Posts:
    110
    Hey iCode, I'm currently in the process of updating the package. Though I can't commit to a date right now. I'll let you guys know when the update is online
     
  39. iCode

    iCode

    Joined:
    May 25, 2013
    Posts:
    32
    Great! Thank you for your prompt response.
     
  40. jtadeo1

    jtadeo1

    Joined:
    Oct 18, 2006
    Posts:
    78
    This looks great! I'm looking at expanding my Photon knowledge all the time.
     
  41. HKSpadez

    HKSpadez

    Joined:
    Apr 24, 2013
    Posts:
    87
    hey there! I'm very interested in your asset, but the main thing I am looking for is lag compensation. I'm already pretty familiar with photon but I wanted to learn more about different methods of handling lag.

    i know its listed under "future episodes" so is there an ETA as to when this will be covered? I'll have my wallet ready for when that is out =)

    @Keith90

    I am actually interested in fighting games as well. as a competitive smash player and FGC i've done quite a bit of research regarding this topic and its not easy.

    http://www.gamasutra.com/view/news/177508/The_lagfighting_techniques_behind_GGPOs_netcode.php

    take a look at this article. it explains GGPO's lag fighting algorithm

    theres also valve's methods of handlin lag:
    https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

    PS: even though i've looked up these different methods i'm hoping the asset will show some sort of implementation to give me a starting point, since everything i've found online so far is just theory and explanation. it would be incredibly helpful to see it in action
     
    Last edited: Oct 16, 2014
  42. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    Dear Oliver or any other member wanting to help.
    I can confirm that the users connecting to an existing server will trigger twice the loading of the selected room. This is how you can replicate it:
    Compile an standalone version of the game and create a room in there. Then open the game inside the editor and join the room from the editor. I know it's being triggered twice because all the Start() methods of all the scripts inside the scene get called twice. If have created breakpoints on all the Start() methods and all of them executed twice.

    This happens very fast so it does not affect the game, but it is affecting my own game which do more things on the Start() methods.

    Please I need to know if this is standard behavior of Photon so I can code a workaround to this issue, or if this is something that can be fixed.

    Thanks in advance
     
  43. HugoPeters

    HugoPeters

    Joined:
    Apr 2, 2014
    Posts:
    18
    This above is correct also on my platform and seems like a (real) bug to me.
    This problem is caused by the MultiplayerConnector class function OnJoinedRoom where there is an loadlevel function.
    The main problem is that " PhotonNetwork.automaticallySyncScene = true; " which means that if a user joins a room the photon network will already load the needed (level/map) and when that level is loaded the OnJoinedRoom gets called (in this case with another loadlevel) . But when a host creates a room it doesnt so thats why the loadlevel is in the OnJoinedRoom.

    I fixed this in the MultiPlayerConnecter in the OnJoinedRoom by only letting the levelload if its the masterclient
    Code (CSharp):
    1.  
    2. if (PhotonNetwork.isMasterClient) {
    3. PhotonNetwork.isMessageQueueRunning = false;
    4. }
    5.  
    6. //** rest of code
    7.  
    8. if (PhotonNetwork.isMasterClient) {
    9.   Application.LoadLevel( currentMap.Name );
    10. }
     
    GregMeach and andrescavallin like this.
  44. SLThompson

    SLThompson

    Joined:
    Feb 7, 2014
    Posts:
    46
    I applied your isMaterClient correction because there is an issue with the displayed game timer for the scene, it remains different still. I was wondering if you had any ideas about how to fix that?
     
  45. grobm

    grobm

    Joined:
    Aug 15, 2005
    Posts:
    215
    I am getting the following error when switching the platform to iOS. It provides these errors only in the xCode Version 6.1.1 (6A2008a) on compile, not in the Unity3D build.

    Suggestions? I have tried updating the latest release of PUN Free, but it still does not fix this issue.

    "_egservice", referenced from:

    "_egsend", referenced from:

    "_egread", referenced from:

    "_eggetState", referenced from:

    "_egdisconnect", referenced from:

    "_egconnect", referenced from:

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Suggestions?
     
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    @grobm: You seem to be mixing PUN+ and PUN Free to some degree?! You could delete the Assets\Plugins\*photon*.* files (e.g. Photon3Unity3d.dll and our .a and .so files) and then re-import PUN Free (which will re-add the files).
     
    grobm likes this.
  47. grobm

    grobm

    Joined:
    Aug 15, 2005
    Posts:
    215
    Thanks tobiass! That did the trick. When are you going to publish your tutorial on querying current rooms that are public?

    This Tutorial has helped me out a lot with my current projects and developments.
     
  48. aanimation

    aanimation

    Joined:
    Oct 23, 2012
    Posts:
    49
    where link to download this project? i need them about learn to research and develop Moba Game
     
  49. BillO

    BillO

    Joined:
    Sep 26, 2010
    Posts:
    58
    PUN Sky Arena in the Asset Store indicates it has been updated. Does that mean it will now work with PUN+ including the chat?
     
  50. detrohutt

    detrohutt

    Joined:
    Feb 13, 2015
    Posts:
    2
    Question.. are there any licensing restrictions on using the code commercially? I don't intend to use any of the assets, just parts of the scripts. I'm working on a 2D space shooter and a lot of the code directly applies to what I'm doing(Respawning, dealing damage, killcounts, death routines, etc). Can I just copy and modify the code as needed or do I need to try and recreate it from scratch?