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. Dismiss Notice

Third Party About Photon Fusion

Discussion in 'Multiplayer' started by rafaelbarretobra, Jul 8, 2022.

  1. rafaelbarretobra

    rafaelbarretobra

    Joined:
    Aug 5, 2015
    Posts:
    11
    Hello everyone, I'm writing a simple rpg in Fusion where the players (Clients) click a button to craft an item. Then I send an RPC to All and check is Runner.IsServer to use the Spawn method to spawn the prefab. This works fine in the server, but for some reason, it's not working on the clients connected to the server.
    Here's the method I'm using. Any thoughts? If there's anyone out there who really knows Fusion, our studio would love to have some classes also.

    Code (CSharp):
    1. [Rpc(RpcSources.All, RpcTargets.All)]
    2.     public void RPC_SpawnPlaceable(string pName, Vector3 location, string playerName)
    3.     {
    4.         print($" {playerName} RPC_SpawnPlaceable: " + pName);
    5.         for (int i = 0; i < placeables.Count; i++)
    6.         {
    7.             if (placeables[i].name == pName)
    8.             {
    9.                if(Runner.IsServer)
    10.                Runner.Spawn(placeables[i], location, Quaternion.identity, null, null, null, false);
    11.                RPC_AlertDMs(playerName, pName);
    12.                     break;
    13.                
    14.             }
    15.         }
    16.      
    17.     }
     
  2. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    38
    Hi,

    There are a few points to consider in this case:

    1. You should avoid using RPCs as, in most cases, it is not necessary when using ClientServer Mode. The Item creation can be part of your Input, for example, so only the local client and the server will receive this information, and the Server can decide if the item will be spawned or not. You can read more about Network Inputs here: https://doc.photonengine.com/en-us/fusion/current/manual/network-input

    2. If you are going to use an RPC, there is no need to send it to all peers, as again, in Client Server Mode, the Server is always the State Authority over the NetworkObject and the client is usually the Input Authority, so you can change your definition to:

    Code (CSharp):
    1. [Rpc(RpcSources.InputAuthority, RpcTargets.StateAuthority)]
    2. public void RPC_Example(){}
    3.  
    Instead of checking if it is running on the Server or not.
    You can read more about RPCs in general here: https://doc.photonengine.com/en-us/fusion/current/manual/rpc

    3. Other than that, we suggest looking at Fusion 101 here: https://doc.photonengine.com/en-us/fusion/current/fusion-100/overview
    It shows the basic features of Fusion, including the use of RPCs.

    --
    Ramon Melo
    Photon Fusion Team
     
    tobiass likes this.
  3. rafaelbarretobra

    rafaelbarretobra

    Joined:
    Aug 5, 2015
    Posts:
    11
    Thanks Ramon. My company is having a hard time trying to grasp some basic concepts. Is there anywhere where we can get some Fusion consulting (paid of course)? Our email is contact@firegamestudios.com
     
  4. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    38
    Hi,

    Please contact us via developer@photonengine.com and we can give you more information about consulting.

    --
    Ramon Melo
    Photon Fusion Team