LoginSignup
0
0

More than 1 year has passed since last update.

【PUN2】AllBufferedViaServerのRPCは後から入った環境においてStart()より前に呼ばれる

Posted at

概要

PUN2(Photon Unity Networking 2)において、photonView.RPC()RpcTarget.AllBufferedViaServerを渡して呼び出したRPCは後から入った環境においてStart()より前に呼ばれるようです。それによって自分が少し嵌りました。検証した内容を備忘録的に記載しておきます。

検証した環境は下記です。

  • Unity2019.4.15f1
  • Photon Unity Networking 2.32

検証

RPC呼び出し可能なHogeRpcFunction()とイベント関数のStart()に確認用にログ出力を追加します。

public class Hoge : MonoBehaviourPunCallbacks
{
	[PunRPC]
	public void HogeRpcFunction()
	{
		Debug.Log("HogeRpcFunction()");
	}

	public void Start()
	{
		Debug.Log("Start()");
	}
}

後から入った環境においてRPCが実行されるように、RPCの呼び出しにおいて、下記コードのようにRpcTarget.AllBufferedViaServerを指定します。

photonView.RPC(nameof(HogeRpcFunction), RpcTarget.AllBufferedViaServer);

最初の環境を起動し、上記のHogeRpcFunction()のRPCの呼び出しを行います。
その後、別のクライアント環境を起動します。
そのクライアント環境において、Start()が呼ばれるよりも前にHogeRpcFunction()が呼ばれることが確認できました(ログ出力の下記画像を参照)。
image.png

RpcTarget.AllBufferedViaServerで呼び出したRPCがStart()で何かしら処理を行っていることを前提にしている場合、正しく動作しないので注意が必要そうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0