Ownership change - weird behaviour

Options
Hi,

I´m experiencing weird behaviour when calling TransferOwnership() function on my shared scene object. After I call mentioned function, I´m observing behaviour of OnPhotonSerializeView() function and every time when stream.isWriting == true, I´m logging "OWNER" to the console. If the stream is not writing, I´m logging "NOT OWNER".

Let´s say I don´t own my object, but TransferOwnership() was just called and I want to become new owner. Expected behaviour is just simple switch between "NOT OWNER" and "OWNER" statement, but the real outcome is "NOT OWNER" -> "OWNER" -> "NOT OWNER" -> "OWNER". It looks like that ownership is changed twice instead of once. Is this correct behaviour? I thought it is possible that I call TransferOwnership() more than once, but I don´t and also Photon debug log "Ev OwnershipTransfer. ViewID 1 to: 2 Time: 359" is invoked only once. Could it be maybe some bug in Photon?

Also, what is the proper way to check if I am a owner of the object? Until now I was using function with this: this.photonView.ownerId == PhotonNetwork.player.ID, but I found out it doesn´t match the real situation. For example, my function tells me that I am a owner, but in fact I´m still reading from the stream in OnPhotonSerializeView(). Is there something more precise for checking?

Thanks in advance for any answers!

Comments

  • crabMan
    Options
    From what I´ve observed until now I can say that the problem with multiple writing/reading switches occurs only when I am taking ownership. When I´m loosing it, everything is ok and the log goes perfectly from "OWNER" to "NOT OWNER".
  • jeanfabre
    Options
    Hi,

    The OwnerId is the property to check to know who's owns it.

    Can you check with the ownership transfer demo? is that demos works as expected or does it produce the same multiple writing/reading?

    Bye,

    Jean
  • crabMan
    crabMan
    edited November 2016
    Options
    Hi,

    thanks for your interest about my problem! I just spent an hour checking behaviour of the ownership transfer demo and it looks like the problem is there as well. I´ve attached this script to the sphere which has PhotonView set to Takeover and Observe option to Unreliable:
    public class TestBehaviourScript : Photon.PunBehaviour {
    
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            // Always send transform (depending on reliability of the network view)
            Debug.LogFormat("IS BALL MINE? {0}  w:{1} r:{2}", IsCubeMine(), stream.isWriting, stream.isReading);
            if (stream.isWriting)
            {
                #region OwnerCheck
                Debug.Log("OWNER!");
                #endregion
    
                #region Info about position and rotation
                Vector3 pos = transform.localPosition;
                Quaternion rot = transform.localRotation;
    
                stream.Serialize(ref pos);
                stream.Serialize(ref rot);
                #endregion
            }
            // When receiving, buffer the information
            else
            {
                #region OwnerCheck
                Debug.Log("NOT OWNER!");
                #endregion
    
                #region Info about position and rotation
                Vector3 pos = Vector3.zero;
                Quaternion rot = Quaternion.identity;
                stream.Serialize(ref pos);
                stream.Serialize(ref rot);
    
                transform.localPosition = pos;
                transform.localRotation = rot;
                #endregion
            }
        }
    
        public bool IsCubeMine()
        {
            return (this.photonView.ownerId == PhotonNetwork.player.ID) ? true : false;
        }
    }
    I´ve also changed PhotonNetwork.sendRate and PhotonNetwork.sendRateOnSerialize to 20, just to make sure it is the same as in my project.

    The result is almost the same as in my project - sometimes the log strings are changing unexpectedly - see the screenshot below that I took just after I clicked the sphere and I got ownership:
    http://imgur.com/xmxNdY3

    You can see that after ownership change evaluation it switches to "OWNER", but next call it is on "NOT OWNER" again. Another next call is switched to "OWNER" and it continues as expected. From my observation it seems like that send rate affects this behaviour, because I tried it also with default send rate (10 I think?) and I witnessed this problem like once from twenty attempts. After sendRate change I´m witnessing it much more often.

  • jeanfabre
    Options
    Hi,

    ok, can you increase the debug log to FULL, then it will log more infos on what's going on internaly.

    you should not need any custom scripts to witness how the demo ownership sphere works, because the color is assigned based on the owner, so with colors you know exactly who's the owner, and there is a yellow arrow above the sphere to indicate who owns it.

    I am not able to replicate this, I am puzzled as to what could be going on on your end. Are you testing on a fresh project?

    Bye,

    Jean
  • crabMan
    Options
    I know that colors are displaying who is the owner, but everything seems to be ok based on this indicator. The problem is just one call of OnPhotonSerializeView() which changes unexpectedly. You cannot see this by eye, that´s why I´m using debug logs.

    Anyway, I just created new project, downloaded PUN package from the asset store and I´ve tried to replicate the problem on the fresh project. In the end I found out that this problem occurs only on non-master client. Can you please try to replicate it following this steps I´ve done?:
    1)Download PUN package from asset store, import it to the clear project
    2)Open DemoChangeOwnerScene, in the script ConnectAndJoinRandom.cs add these lines to Start method:
            PhotonNetwork.logLevel = PhotonLogLevel.Full;
            PhotonNetwork.sendRate = 20;
            PhotonNetwork.sendRateOnSerialize = 20;
    3)GameObject OwnershipSphere, change PhotonView observe option to Unreliable
    4)Add the script from my previous post (that one with OWNER logs) to the OwnershipSphere, let it being observed by PhotonView. Delete/comment part with position and rotation serialization, this is already covered by observing Transform of the object - so the final script will contain only Log.Debug() calls.
    5) Make the build and start it as a master client, then hit play in the editor and join the room.
    6) You are not master in the editor instance and the sphere is not yours, so click the sphere, obtain ownership and take a look in the console. I did it like this right now and the logs gave me this:
    http://imgur.com/bRvfssl

    It was first time I clicked the sphere and it seems like there are two unexpected "NOT OWNER" logs (sometimes there is only one and sometimes it is totally ok). Can you let me know if you can replicate this behaviour? Thanks again for helping!
  • crabMan
    Options
    Hi, did you try to replicate my problem?
  • jeanfabre
    Options
    Hi,

    I see, yes I can repro this.

    Basically, I'll double check with the engineers to see if this is something they are aware of, and if it's a feature or bug. But my first guess is that events being sent must be acknowledged, and the stream associated with the event already contains the writing or reading property, and so regardless of who's the actual owner, the stream has its own protocole already in place.

    it's definitly linked to the reliable state of the photonView, so "unreliable" likely means actually "unreliable" :)

    can you confirm that if you switch to reliable it doesn't have this issue?

    I would simply double check manually like you do with your IsCubeMine() before actually writing or reading which will simply make it safe for your case if you need to keep option to unreliable.

    and to answer your initial question, use PhotonView.IsMine() to check who owns this view, and yes, it's separate from the stream reading and writing as you witnessed, I'll get back to you on wether this is a bug or not in this situation.

    Bye,

    Jean
  • crabMan
    Options
    Thanks for your advices, I´m interested if you find out something with engineers.

    Anyway, I did what you´ve asked me for and I´m afraid the problem is still there although it is not occuring so frequently. I changed the observe option on Sphere´s PhotonView to Reliable Delta Compressed and this is my last attempt:
    http://imgur.com/a/mhsRi

    All the settings in the project remained the same as in my previous attempts, only observe option has been changed. What you can see is log from non-master client when taking over the ownership. But it is really hard to replicate this, I´ve tried to takeover the ownership like 30-times and it was like this only in two cases, so I guess there will be some relation between observe option and this behaviour.

    Let me know when you will know if it is as bug or feature, please. Thanks again for helping!
  • jeanfabre
    Options
    Hi,

    ok. and meanwhile, make sure you test for isMine before reading and writing and simply ignore the stream when you detect this situation while I get to the bottom of this issue.

    Bye,

    Jean