- Home /
Problem with PhotonView.RPC
hi, i am new to unity and photon networking and i am converting my Maltiplayer game made using ultimate unity networking into Photon networking. with the tutorial(came with sdk) i have converted my all unity networking code to photon networking using photon converter. i have fixed all the bugs but at runtime i have having problem with PhotonView.RPC method. it is giving me this error.
"PhotonView with ID 1000 has no method "SetCurrentCharacter" that takes 0 argument(s):" and my code is as follows.
void SetupAvatar(int characterId)
{
if (character != null)
PhotonNetwork.Destroy(character);
character = (GameObject)PhotonNetwork.Instantiate(characterPrefabs[characterId], Vector3.zero, Quaternion.identity, 0);
// Sync Avatar configuration
if (PhotonNetwork.isNonMasterClientInGame || PhotonNetwork.isMasterClient) {
Debug.Log("Before Set Current character!!!");
photonView.RPC("SetCurrentCharacter", PhotonTargets.AllBuffered);
}
}
[RPC]
void SetCurrentCharacter(PhotonViewID characterViewId)
{
Debug.Log("Set Current Character Method!!!");
PhotonView view = PhotonView.Find(characterViewId.ID);
if (view == null)
{
PhotonNetwork.Destroy(gameObject);
return;
}
character = view.gameObject;
character.transform.parent = transform;
character.transform.localPosition = Vector3.zero;
character.transform.localRotation = Quaternion.identity;
_animation = character.animation;
if (_animation != null)
enabled = true;
}
i do not know how to get the photon View id so i can pass it as a parameter in this method.
any help will be greatly appreciative. thanks.
Answer by BassaForte · Jan 05, 2014 at 06:53 AM
Your method is looking for a PhotonViewID, which you don't specify in your RPC call.
Should be: photonView.RPC("SetCurrentCharacter", PhotonTargets.AllBuffered, );
Answer by UberLax · May 26, 2014 at 02:05 AM
Your RPC called SetCurrentCharacter accepts one argument of type PhotonViewID. When you call the RPC
photonView.RPC("SetCurrentCharacter", PhotonTargets.AllBuffered);
You have to specify the arguments that the RPC takes. Example:
photonView.RPC("SetCurrentCharacter", PhotonTargets.AllBuffered, photonView.viewID);
Note: There is a limited selection of data types you can pass as RPCs. Look here for a list of available types.
Answer by CrashTest · Mar 10, 2016 at 09:12 AM
Your SetCurrentCharacter method has attribute RPC. It must have attribute PunRPC like this ...
[PunRPC]
void SetCurrentCharacter(PhotonViewID characterViewId)
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Photon - Loads a level but doesn't spawn player. 1 Answer
How to instatiate two players simultaneoulsy before loading level 1 Answer
Photon multiplayer room make disappear in lobby when room is getting full 1 Answer
Unity multiplayer solutions: Photon, Unity Networking - what else and in what way is good? 0 Answers