Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Photon Fusion

Discussion in 'Multiplayer' started by ramonsmelo, Apr 5, 2022.

  1. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Photon Fusion - Multiplayer Network Solution

    Download: Photon Fusion Download Page


    Overview:

    Photon Fusion is a new high-performance state synchronization networking library for Unity. With a single API, it supports many network architectures such as dedicated server, client-hosted, and shared/distributed authority.

    It is built with simplicity in mind to integrate naturally into the common Unity workflow, while also offering advanced features like data compression, client-side prediction and lag compensation out of the box.

    Fusion implements a robust tick-based simulation and state snapshots system with built-in reconciliation. This allow Fusion to work seamlessly with non-deterministic libraries like Unity PhysX.

    Besides the cloud-based shared mode where each client has full authority of its own objects (like PUN before it), Fusion includes two full server-authority modes:

    • a strict Client/Server setup with dedicated headless Unity instances; or,
    • a player-as-host with one of the clients working as both server and client (Host);
    Important Links:
    Requirements:
    • Unity 2020.3 or up.
    Supported Platforms:
    • Microsoft Windows
    • macOS
    • Android (including Quest)
    • iOS
    • Linux
    Coming soon:
    • Nintendo Switch
    • Xbox One
    • Xbox Series X & S
    • PS4
    • PS5
    Available Samples:
    • Fusion Dragonhunters VR [link]

    • Fusion Karts [link]

    • Fusion Razor Madness [link]

    • Fusion Tanknarok [link]


    Release History
    • 1.0.0 Stable (Mar 17, 2022) [link]
     
    Last edited: May 10, 2022
  2. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    304
    Awesome. On the kart one, I checked the highlights but didn't see mention of CSP. Is the Kart demo using client or server auth?
     
  3. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Hi,

    The Fusion Kart demo works in ClientServer topology, so the Server is always the State Auth, while the Client performs the simulation prediction.

    --
    Ramon Melo
    Photon Fusion Team
     
    Punfish likes this.
  4. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,167
    I've used Photon Fusion beta and I can honestly say it's the best networking solution for Unity out there. Great job guys!
     
  5. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Looks awesome!
    Seams like the networking API my top-down shooter needs.
    Good work.
     
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,724
    I've been doing some basic testing to become familiar with Fusion before I start to migrate my RPG from PUN to Fusion.

    Initial results look very promising, I set up a test for my character controller to check movement synchronization (using the supplied network position/rotation component) and at one point had 9 clients connected to the same room, all of which were moving pretty much constantly and it never exceeded 1 msg/s.

    Something similar with PUN with the same quality of synchronisation using the built in components would have resulted in far higher msg/s count, probably in the 100s.

    Anyhow, @tobiass the main reason for my post is to ask if there is an equivalent to PUN InstantiationData, I'm guessing there is, but I've been unable to find mention of it in the docs/examples.

    Thanks :)
     
    Last edited: Apr 24, 2022
  7. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Ok, I started with my game, first following the tutorial, and later changing the code to fit my game, and the first results are incredibly good, I love how easy to use is fusion and how good it works. But, I want to change the matchmaking code from the tutorial. I made so first tries to connect as a client to a random room by deleting the room name, get the StartGameResult and if the result is not OK I start a game (without name so fusion generates a random name) as host. When I press the button I see in the debug that failed to join a room, but it doesnt try to create one. Here is a simplified version of my code:
    Code (csharp):
    1.  
    2. StartGameResult res = runner.StartGame(someArgs);//It will try to join a random room, since no room name has been specified
    3. if(!res.Ok) runner.StartGame(someArgs)//No room found so creates a new one with random name.
    4.  
    I tried with shared mode, but the 2nd player spawned 2 instances, the 3rd one 3 and so on.
    I havent touched the spawn code.

    What Im doing wrong @tobiass ?
    Should I use shared or hosted mode for a 1v1 top-down shooter?
    If shared, the code of fusion 100 series works for shared mode?
     
    Last edited: Apr 24, 2022
    zoeyducoeur likes this.
  8. Alex94i60

    Alex94i60

    Joined:
    Sep 29, 2018
    Posts:
    6
    Hello, I downloaded Kart a while ago and thought it was an excellent multiplayer game pack, but I want to modify a part, it will count down three seconds when entering the game opening, press the forward button before the GO text appears to get a boost is so short , I think the timing is too difficult to grasp, so I want to modify the time to be longer (for example, pressing the forward key when the word GO appears, still allows the boost), I have sent a letter to Photon Team Japan, but can only give me suggestions, so I have seen similar code in KartController.cs(OnRaceStart), but no matter how I modify it, I can't extend the time. I don't know if you can give me modification suggestions, thank you!
     
  9. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Hi, yes, it is possible.
    When spawning a new NetworkObject, just fill the OnBeforeSpawned() callback, it will be invoked before the NO is spawned and can be used to fill its state before it is synchronized on the network.

    Take a look here for more info: https://doc.photonengine.com/en-us/fusion/current/manual/spawning#runner_spawn

    --
    Ramon Melo
    Photon Fusion Team
     
    Munchy2007 likes this.
  10. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Hi, simple enough:

    Code (csharp):
    1.  
    2. var result = await runner.StartGame(new StartGameArgs() {
    3.   GameMode = GameMode.AutoHostOrClient,
    4.   // ...
    5. });
    6.  
    This will start your peer in either Host or Client mode automatically depending if it is creating or joining a Game Session.

    If you start the peer at the exact same time, due to the Session creation being an asynchronous process, it can take a bit of time, then your client and end up creating new Sessions because the other one could not be found yet.
    The Fusion 101 may require a few changes to work in Shared Mode, but the core implementation will still work.

    --
    Ramon Melo
    Photon Fusion Team
     
    fumobox and r31o like this.
  11. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,724
    That's great, thanks for the info :)
     
  12. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Thanks a lot! You saved me hours of searching!
     
  13. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,724
    @ramonsmelo How can I prevent automatic synchronization of scenes between host and clients. With PUN I used to set PhotonNetwork.AutomaticallySyncScene to false, but I can't find the equivalent in Fusion.

    Thanks
     
    Last edited: Apr 26, 2022
  14. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Hi,

    Fusion does not even imply that scenes must be synchronized at all.

    The SetActiveScene method only does the following:
    - sets an int that clients can read
    - the actual scene loading and matching of scene-bound NetworkObjects is done by the SceneObjectManager implementation (which is a sample class, that you can freely modify or implement differently).

    You can totally ignore that method.

    In production cases, we suggest you network which scenes should be loaded as a NetworkArray or any other form you choose, and you modify/create a SceneObjectManager implementation that attaches the network objects from the server scene + instantiates the matching right prefabs on the clients...

    The mechanism how this works can be seen on the sample implementation as I mentioned.
     
    Munchy2007 likes this.
  15. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,724
    Hi perick, thanks for clarifying that. :)
     
  16. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    One question:
    There is some way to prevent cheating in fusion or pun?
     
  17. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    That is quite an open question, but this usually means Server Authority over the Game State, and this can easily be accomplished with Photon Fusion running in ClientServer mode, in which the client can only predict their game, but the truth about the game state always comes from the Game Server. It will help to solve most cases.

    Take a look here for more information:
    - https://doc.photonengine.com/en-us/fusion/current/getting-started/fusion-intro
    - https://doc.photonengine.com/en-us/fusion/current/manual/state-transfer

    --
    Ramon Melo
    Photon Fusion Team
     
    Lukasz_CVR likes this.
  18. RiccardoAxed

    RiccardoAxed

    Joined:
    Aug 29, 2017
    Posts:
    114
    Hi, I already used Photon PUN with success for a simple multiplayer game, a few years ago, and now I should start a bigger project, sort of 3D Chat-Metaverse like experience, with many users interacting in various ways in shared rooms.
    So, i would pose some questions to better understand my potential options and costs:

    1. For my project I guess i should have a go with Fusion but exploring your website I see there's at least another Unity option called Quantum, what are the main differences between it and Fusion? (Allow me to give you a little tip: a feature comparison table between all your products would be very, very appreciated :)).

    2. My virtual experience should rely on multiplayer support as well as voice/text chat, so is it possibile to subscribe to Fusion + Voice + Chat services and use them all together in the same app?

    3. Assuming the point 2. is true - as I guess - I would better understand what could be my costs. Should I simply sum all the costs from every service's pricing page, or there's some other formula to combine the prices? Could you possibly give me some practical, ballpark example: let's say a first scenario with 50 people potentially interacting and chatting (voice and text) and another bigger case with 500 people or more.

    Thank you for your attention!

    Riccardo
     
  19. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    1. I dont know
    2. You can do it.
    3. Fusion price + voice price + chat price.

    I might be wrong, but I think that is.

    Also make your game run on a server, otherwise the host's computer will die.
     
    RiccardoAxed likes this.
  20. RiccardoAxed

    RiccardoAxed

    Joined:
    Aug 29, 2017
    Posts:
    114
    Thank you anyway for the answer, hope the Fusion developers would confirm or rectify if necessary.
    Another question that came to mind: does Fusion support WebGL too?
     
  21. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Last time I check, I think it was in the todo list.
     
  22. whalefood_

    whalefood_

    Joined:
    Sep 5, 2012
    Posts:
    2
    Fusion seems really cool. But I'm wondering if it will work for my use case. I'm trying to set up a fusion server in a docker container. And while it functions, the connection type of all the clients connecting to it is always 'relayed' rather than 'direct', which isn't ideal. I've exposed a port (8080) and passed that port in the start args on the server
    Code (CSharp):
    1. startArgs.Address = NetAddress.Any(8080);
    Is there anything else that's needed? Maybe some additional port settings somewhere? Or is there any way to see some sort of messaging from photon about why the direct connection failed?
     
  23. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    Hi, Why does it return null?
    Code (CSharp):
    1.  
    2. NetworkObject networkPlayerObject = runner.Spawn(playerPrefab, spawnPosition, Quaternion.identity, player);
    3.  
    I use Host-Client mode, and create player in OnSceneLoadDone or OnPlayerJoined.

    I want to attach a camera to a player, but I can't get a link to it. The player himself is being created
    How do I get a reference to an object?
     
  24. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    Do you have a discord or telegram community?
     
  25. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    You dont need the networkobject. Change it by gameobject, and then use its transform, or get the networkobject…
     
  26. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    Using the standard Instantiate? Or is there some special method in Photon Fusion?
     
  27. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    I probably need "Spawn Prediction", will it help?
     
  28. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    In the code above change from NetworkObject to GameObject
     
  29. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    NetworkRunner.Spawn - return Network object, i cant change from NetworkObject to GameObject
     
  30. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Oh :confused:
     
  31. aldetkovgd

    aldetkovgd

    Joined:
    Jan 9, 2021
    Posts:
    9
    12 hours of trial and error = found the "Spawned" method I need in NetworkBehavior :eek::confused:o_O


    Code (CSharp):
    1.         public override void Spawned()
    2.         {
    3.             base.Spawned();
    4.             if (NetworkCore.Instance.Runner.LocalPlayer == Object.InputAuthority)
    5.             {
    6.                 NetworkInputManager.Instance.Init(GetComponentInChildren<CameraAnchor>());
    7.                 gameObject.AddComponent<AudioListener>();
    8.             }
    9.         }
     
  32. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    You can remove base.Spawn()
     
  33. whalefood_

    whalefood_

    Joined:
    Sep 5, 2012
    Posts:
    2
    I found a NetworkRunner.NATType I can check, but the value doesn't really tell me anything. It's FullCone on both my client and server
     
  34. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    1. Please take a look here: https://www.dropbox.com/s/ovvz3p8k5csj2gj/fusion_productsheet.pdf
    2. Yes it is possible without any issues.
    3. All products are CCU based, and each product uses its own CCU and AppID, so yes, you need to consider to costs of each individual project.

    --
    Ramon Melo
    Photon Fusion Team
     
  35. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    The support is in development. We already have internal working versions of it, but we still need to solve a few details before the release.

    --
    Ramon Melo
    Photon Fusion Team
     
  36. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Yes, that should be enough to enable your clients to connect to your server.
    Can you send us the logs from your clients and server to our support email? developer@photonengine.com

    --
    Ramon Melo
    Photon Fusion Team
     
  37. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Yes, the link is in the first post.

    --
    Ramon Melo
    Photon Fusion Team
     
  38. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Why fusion is more expensive than PUN?
     
  39. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,081
    Why there are still limits similar to pun by default?
    • 500 Msg/s per Room *
    • Up to 16 Peers per Room *
    Does pricing increases if those are lifted after contacting? Is Fusion suitable for bigger games like battle royales?
     
  40. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    500 ccu in Photon Pun costs 95$ in fusion costs 125$. With 500 is not a great difference, but with 2000 ccu the diference is more than 100$
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,991
    Are the limits still on the Fusion pricing page?! This is a copy paste error. Some limit is likely but it's not going to be the one of PUN 2.
    Fusion aims for higher player counts and the message frequency is also higher. Battle Royale is definitely possible.

    Sorry for the scare about the messages/sec and peers/room :)
     
  42. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    So, fusion will have more free ccu?
     
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,991
    This is not planned, no. The 20 CCU are supplied to test and start development. If you need more, we kindly ask to buy a subscription or the 100 CCU plan, which has a one time fee for a complete year.
     
  44. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    I want to make a fps game where you can host lobbies with custom settings to play with 1-50 other players.
    Fusion seams to be what I need, but if there are 50 players in the lobby, the host's fps wont be incredibly low?
     
  45. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,081
    I guess you have to use:
    Meaning you also have to pay for dedicated servers as from what I remember Fusion price doesn't cover them.
     
  46. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    Im poor.
    I want to release my game on steam some day. Do they have some server hosting for me?
     
  47. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    37
    Hi,

    We don't offer the service of Dedicated Server Hosting, for that you can use Gameye, and Multiplay, among others, for example.

    And yes, if you plan to run a 50+ player server, it is suggested to go with a Dedicated Server, as client-hosted games are bound to the client machine processing power and internet capabilities, which is usually not meant to handle a such a number of players.

    Photon Fusion is really optimized to handle as many clients as possible, as an example, take a look at our Fusion Battle Royale stream here. The server was running from a local dedicated server from one of our devs and it worked fine with around 30 players, but we have internal tests with 120 players.

    --
    Ramon Melo
    Photon Fusion Team
     
  48. chaaards

    chaaards

    Joined:
    Dec 22, 2016
    Posts:
    6
    I've question about OnInput

    Does every "Input" must be stored into a Networked Component (like Rb2D, etc)?
    To be able to synced with other player...

    I've an issue where Client not synced with other Client or Host. While Host is always synced with other Client.
     
  49. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    How did you use the input?
    In a client hosted game, only the host can modify things, so, if you are doing something from a client, wont work, but the host can do whatever he wants with his gameObject. If you want to make the clients control their gameObject, give them authority.

    I think that is your problem.
     
  50. chaaards

    chaaards

    Joined:
    Dec 22, 2016
    Posts:
    6
    I am following Fusion 101 to move my character.
    But, I want to play move anim when the character is moving.

    The way I used now is, I store the input to normal variable (on FixedUpdateNetwork), and pass the variable to the animation script.
    Anim script will see the variable value to determine play/stop anim.
    It doesn't work on the Client, on the Host side it works.