Rpc parameters

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Rpc parameters

Zeohack
2021-06-30 07:49:46

hi.. I've been dealing with rpc for a while, but I couldn't figure out how to write method parameters, especially piece and Vector2Int gridpoint parameter method, how should I write them when calling the method with rpc? I will be glad if you help. here are my codes..

MoveSelector Script..

Void Start(){  
Pw = GetComponent<PhotonView>();  
}

 Void Update(){  
Ray ray = cam.ScreenPointToRay(Input.mousePosition);  
         
        RaycastHit hit;  
        if (Physics.Raycast(ray, out hit))  
        {  
            Vector3 point = hit.point;  
            Vector2Int gridPoint = Geometry.GridFromPoint(point);  
//  
       if (pw.RPC("PieceAtGrid",RpcTarget.All, gridPoint) == null)  
                {  
                 pw.RPC("CapturePiece",RpcTarget.All, piece, gridPoint);  
}  
}  
                   

Gamemanager Script...

[PunRPC]  
public void CapturePiece(gameObject piece, Vector2Int gridPoint)  
{  
  //  
   //  
}  




  
[PunRPC]  
public GameObject PieceAtGrid(Vector2Int gridPoint)  
    {       
        if (gridPoint.x > 7 || gridPoint.y > 7 || gridPoint.x < 0 || gridPoint.y < 0)  
        {  
            return null;  
        }  
        return pieces[gridPoint.x, gridPoint.y];  
    }

Geometry Script...

public class Geometry  
{  
    static public Vector3 PointFromGrid(Vector2Int gridPoint)  
    {  
        float x = -3.5f + 1.0f * gridPoint.x;  
        float z = -3.5f + 1.0f * gridPoint.y;  
        return new Vector3(x, 0, z);  
    }

    static public Vector2Int GridPoint(int col, int row)  
    {  
        return new Vector2Int(col, row);  
    }  

Comments

Tobias
2021-06-30 09:47:20

Vector2Int is not a type that PUN de/serializes out of the box. It needs to be added as custom type (or you use Vector2).

What are the issues you run into?

Zeohack
2021-06-30 09:56:27

I need to use the gridpoint parameter to call the method, how can I add it as a custom type?

Tobias
2021-06-30 15:39:12

Have a look at CustomTypesUnity.cs. It registers a few types of Unity as custom types for Photon.
There is also a doc about serialization in PUN.

Zeohack
2021-06-30 15:42:34

thanks I think I need to adapt it to my project as Vector2Int by looking at Vector2 examples

Back to top