Some way to RPC or Serialize Parenting??? - PhotonRealtime

I'm loving re-writing my single player prototype in Photon.

But my construction system doesn't seem to like it too much. I can't seem to tell everybody that this has been parented to that when it was instantiated.

Is there any way at all to sync parenting between objects? I can't really post my system's code here to the public... It would be nice to find somebody I could collaborate with on this. The unity forum won't seem to let me post anything photon related in the collab section...

Comments

  • Just use an RPC that handles the parenting. You can even have it send to PhotonTargets.All and have the local client's parenting handled in that rpc as well so avoid writing 2 methods. Or use PhotonNetwork.netowrkingPeer.OpRaiseEvent (I've tried PhotonNetwork.RaiseEvent and it doesn't work, so... maybe devs can enlighten that subject if need be). You'll want to set up your own even system if you go that route, but it's honestly better than RPCs in some/most cases. Good luck! Also, consider writing a mock example if you have code you can't share. :)
  • I believe I've found a way around it :) By removing objects that aren't required in planning the structure, if you don't own them. (I.E, the person planning is the only one who can see them, so they should only exist for them).

    It is probably not optimal.. But I will optimize later. I'm a week into Photon.
  • So i dId get this fixed.

    Now I am trying to implement OnApplicationQuit.

    It seems when ApplicationQuit is ran, you are automatically disconnected from Photon.

    I have autocleanupplayerobjects disabled, so things you "Build" are left in the world after you leave. Which works, except your player prefab is still standing there where you quit.

    So I was hoping to cancel Alt-F4/ X'ing out. Or atleast, when you did quit, to destroy your player prefab. Though it doesn't seem to want to work. I can cancel the application quitting, but seems it disconnects me from the room no matter what.

    Any thoughts?

    This is on the player.
    public void OnApplicationQuit(){
    	PhotonNetwork.Destroy (this.gameObject);
    }
    

    The network destroy works fine, if I do it from a key input.
    if (Input.GetKeyUp (KeyCode.KeypadPlus)) {
    	PhotonNetwork.Destroy (this.gameObject);
    	Application.Quit();
    }
    

    It destroys your prefab, then kills the application. I would much rather have a window that pops up when you X out or Alt F4 that asks you if you're sure. Yes/No blah blah blah. But without disconnecting you from the room/lobby.
  • Unity will call all implementations of OnApplicationQuit and one of them is in PUN to disconnect (else the editor gets into trouble with background threads or so).
    Disable the OnApplicationQuit in PUN or call it only when you actually quit.

    As you can't be sure if a closing app CAN send something still, you should clean up the leaving player's character in the Master Client or individually in the clients. At least the Master Client is able to Remove() GOs of other players, so you could clean up.
  • Well thats what I was attempting to do by calling the Destroy on app Quit.

    I'm not sure how I would have the master client remove a player's prefab from the room. I can't seem to tell anybody on applcation quit that I've gone, or I would just destroy the prefab that way.

    So how do I stop PUN from disconnecting when i cancel application quit?
  • > So how do I stop PUN from disconnecting when i cancel application quit?
    Check out PUN's code and find OnApplicationQuit(). Disconnect() will be called in there. Comment out this piece but make sure you call Disconnect() in your own code (after the dialog).

    When a player's client gets closed, the others always get a callback about the player leaving. In worst case, it takes a moment to time out a connection if the Disconnect() wasn't sent.

    Implement void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { ... } as described in PhotonNetworkingMessage.