Search Unity

Simplest Facebook SDK multiplayer setup

Discussion in 'Multiplayer' started by chanfort, Jan 2, 2015.

  1. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I am interested how it would be possible to setup simplest Unity multiplayer game for Facebook SDK? It doesn't need to be very detailed - I just need some solution that one player could control one GameObject, while another player could control another GameObject in the same scene at the same time.

    I would prefer to use Unity build-in Network system without using any Photon or some other assets.
     
  2. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590
    Any ideas on this? I am about to do the same thing, with a turn-based game. I am leaning towards Photon, but wondering if there are alternatives.
     
  3. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I am more keen not to use Photon or any other external tool, as there is a build-in pipeline right in the Unity. Here I found quite good tutorial, which covers basic networking:
    http://cgcookie.com/unity/2011/12/20/introduction-to-networking-in-unity/
    On the other hand there is recently released 3 parts how to set up simplest Facebook SDK with explanation from scratch:


    What is interesting part now is how to combine these two things into one working pipeline, as I didn't found no single discussion about this.
     
    vitalie8484 likes this.
  4. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Facebook login and databases are pretty easy to do using Yahoo Games Network, and it also lets you run custom serverside C# code on its cloud servers.
     
  5. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Looks interesting, I will check Yahoo Games Network. P.S. are there some tutorials you would know, which would cover basics for this?
     
  6. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    I don't know about tutorials. They have a wrapped-up login system for Flash games to use, which handles all the UI stuff for you, but with Unity you'll need to make the UI yourself, or use the Facebook plugin from the Asset Store. The SDK includes some examples - the Unity one only covers game networking, but you can also look at the Flash examples to see how to use their APIs for things like database storage, shop purchases, analytics, etc.
     
  7. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Well, UI is not a problem - you can check my current Facebook game:
    https://apps.facebook.com/tales_of_eightrivers
    where I used new Unity 4.6 UI system. It's also not about login system, as login is basically just authentication check.

    The biggest issue is how to set up multiplayer part, that (lets say) I and my friend would be able to join the same match at the same time and that we would be able to see each others actions right through web browser (in Facebook, Yahoo, etc.). More particularly I am keen about setting up master servers, IP adresses, etc., and how Facebook will recognise that. Basically it's a question how to add multiplayer functionality to already existing game, which is already set on Facebook as single player game.
     
    Last edited: Mar 17, 2015
  8. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Oh I see, I thought you'd need to implement the facebook connect UI but I guess it does it for you. The webplayer crashes Chrome when leaving your game though. :)

    If you just want players to be able to host a session or join a session, with simple state synchronization for some gameobjects, then you may be OK with Unity networking. It's the only thing that will let a player host in the webplayer, in any case. Pretty much anything in the webplayer other than Unity's built-in networking needs to relay through an external server as peer-to-peer sockets are not generally supported.

    I guess what's still not clear to me is what you mean by combining Facebook with Unity networking. I don't see much scope for interaction between those features. I might be just shortsighted though :)
     
  9. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    There was an article, that chrome will not support Unity webplayer, so I am not surprised:
    http://blogs.unity3d.com/2014/10/28/the-future-of-web-publishing-in-unity-an-update/
    Try Firefox, it should work much better with webplayer build games.

    That's interesting point - I was thinking actually what is going on with servers when webplayer build is on Facebook: first connection is going through Facebook, original build is saved in e.g. dropbox and multiplayer master server would be somewhere in Unity (if used Unity build-in networking)? Do I miss something here?
     
  10. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    No, you got it right. The webplayer plugin lets your code run in the browser pretty much the same as it does natively, so once it's running it can mostly do anything native code can do. The exceptions are things that are disabled for security reasons, but it's not really anything to do with Facebook. They just serve up a wrapper around your game, and provide services like authentication if you choose to use them.
     
  11. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Sounds good. If it will work, I will probably make tutorial myself at some point how to make a simple Facebook multiplayer game :)
     
  12. Abhijit-Mukherjee

    Abhijit-Mukherjee

    Joined:
    Jan 9, 2015
    Posts:
    193
    Facebook multiplayer game !! wow !! do we have any tutorial yet .
     
  13. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Not yet, as I am still working with Facebook API and it seems like Facebook at the moment doesn't support Unity 5 yet.
     
  14. narger

    narger

    Joined:
    Dec 2, 2014
    Posts:
    51
    If you nave any notice about multiplayer via facebook let us know
     
  15. Abhijit-Mukherjee

    Abhijit-Mukherjee

    Joined:
    Jan 9, 2015
    Posts:
    193
    We are watching this post .. Please update us ..
     
  16. dhpandya

    dhpandya

    Joined:
    Mar 12, 2016
    Posts:
    2
    Has anyone got anything futher in this thread i am in real need of it
    Please share if you have found anything, any alternative just any help for multiplayer game development(majorly facebook even other solutions will do)
     
  17. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Thanks for a reminder! I was working a bit more afterwards and on November I made a combined tutorial myself of how to set up simple Facebook game:

    And I released my own free game "Tales of Eightrivers" based on this approach. However, it's not exactly multiplayer, as I am still quite confused about multiplayer part. It seems like it would be needed a host or matchmaker servers to communicate between players. However, most of such servers are not free, what makes additional difficulties. On the other hand, on LAN it can be created simple host server on one of players computer. However, when we are outside of LAN, this approach stops working. If somebody knows how to setup online multiplayer, which would work not just on LAN without using matchmaking services, it would be a great start.
     
    Last edited: Apr 15, 2016
    jawadzaib3 likes this.
  18. Abhijit-Mukherjee

    Abhijit-Mukherjee

    Joined:
    Jan 9, 2015
    Posts:
    193
    First of all A BIG BIG THANKS for the tutorial ... We also used dropbox as a server for facebook game .. But I have noticed that after converting to openGL its become a very big file and it really very time-consuming to download the game from dropbox in facebook canvas .. rendering is very slow and big waiting time ... Do you feel the same ? If so then what will be the solution .
     
  19. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Yes, I know that problem. The solution is to use asset bundles. I have another video of showing how to create them:

    You can put mostly textures, audio files and other data files, which takes most of the space. Once the asset bundle is created, copy it to dropbox public folder and when downloading, use that link. In that case asset bundles will be no longer in the project and initial loading time of WebGL build will be increased. Player will be downloading the data from your dropbox while playing.
     
    Abhijit-Mukherjee likes this.
  20. Abhijit-Mukherjee

    Abhijit-Mukherjee

    Joined:
    Jan 9, 2015
    Posts:
    193
    Thank you ..... Very much ...
     
  21. jawadzaib3

    jawadzaib3

    Joined:
    Mar 9, 2016
    Posts:
    1
    Hello!
    I have check your tutorial and it was great start. Have you implemented Multiplayer Feature in Facebook Game or have you any tutorial for that? If so, please share it with me. I would be interested in following that tutorial

    Thanks