Client-server initialization/deleting of items

Options
pavelbaslak
edited April 2014 in Photon Server
Hello.
First of all, I would like to thank Exit Games team for such a nice tool as whole Photon line.

I have a such problem over here.
I have a game, 4 people multiplayer.
There are spawnpoints on a level, when user enters its area - it instatiate a monster like this:
[code2=csharp]masterClientController.RPC("InstantiateMob", PhotonTargets.MasterClient, go.name, this.transform.position);[/code2]
and InstantiateMob function, where I use InstantiateSceneObject, because I want a monster to stay on scene if master client will be disconnected:
[code2=csharp][RPC]
public void InstantiateMob(string name, Vector3 CoinLocation)
{
PhotonNetwork.InstantiateSceneObject(name, CoinLocation, Quaternion.identity, 0, null);
}[/code2]
Like I understand, Master Client should instantiate a gameobject in his scene, and other players should see that monster, it should be 1 monster for all 4 people. But, every user has its own monster, not common for all, other people cannot see monster on their clients. What is the problem here, what I do wrong?

Second problem is:
When I want to destroy monster GameObject from master client side( client what have created room) I get next error on another player side(usual client):

Can't execute received Destroy request for view ID=8 as GO can't be found. From player/actorNr: 1 GO to destroy= originating Player=2

It works the same, when I am destroying monster from usual client side, master client works fine, but usual client has the same problem.

The way how do I delete monster is further:
on moster object, what have been created in the way that I have written above, with InstantiateSceneObject on masterclient
[code2=csharp]GameMaster.GM.masterClientController.RPC("DestroyGO", PhotonTargets.MasterClient, character.GetPhotonView().viewID);[/code2]

and DestroyGO method:

[code2=csharp][RPC]
public void DestroyGO(int photonViewID)
{
PhotonView view = PhotonView.Find(photonViewID);
if (view != null)
{
PhotonNetwork.Destroy(view);
}
}[/code2]
What is wrong here? Have tired a little with trying to handle it bymyself. Please help.
Thank you.

Comments

  • Tobias
    Options
    1. I don't know exactly why you get 4 mobs but if any client can call the RPC, then in worst case, each player will ask the Master Client to spawn a mob and then you obviously get more than one.
    You have to check how often the RPC gets called and by who. Debug that and you should be on track to solve the mystery.
    Be aware that if you target the MasterClient, that player might be leaving before it got your message. Then it will become lost (it's NOT automatically sent to some other player who is the new master client). This might lead to bugs if you don't work around it.

    2. Every PhotonView has a owner. If the PhotonView is a scene view, then the Master Client (whichever client that is at the moment) will be the owner. Only the owner can destroy such a PhotonView.
    What is the error you get? Something must be in the log.