Assign owner to PhotonView

Options
I have a very simple two player mage duel game I want to make multi-player. So I already have a 'player' and 'opponent' object in the scene each with the same 'spellcaster' script. What I want is a PhotonView with an ownerid of 1 to go to one of these objects and an owner of 2 to the other. I know how to initialize a prefab and assign an owner... the issue here is I'm using DF GUI and all the property bindings... I'd like not to have to mess with any of that. I suppose I can abstract out all the properties and refactor but ideally I would just add a PhotoView to each and then one player gets one and another player gets the other. I only need to call a 'castspell' rpc and then have updates on health/energy. I can put an AI script on both players and they will fight to the death so I expect it won't be that hard to implement multiplayer... but I struggle a bit at assigning the ownership to Photonviews.

Comments

  • Tobias
    Options
    The simplest way would possibly be to make the characters prefabs. On those prefabs, you add the PhotonView. Each client/player then calls Instantiate() for it's own character and thus becomes owner implicitly. Then it's pretty easy to keep control of both characters and send what you need to send.
    Take the time to work through the Marco Polo Tutorial once for the basics. This should more or less apply to your game, too.
    http://doc.exitgames.com/en/pun/current ... marco-polo
  • DuaneDog
    Options
    Many thanks for writing me back. I definitely can do the prefab initialization. What I've learned in doing more production Unity game development is to NEVER use the "drag and drop" method to wire things together. This has really impacted me with the data binding with DF GUI. See, all my GUI's are property bound to my objects already in the scene. So when I initialize from a prefab, all that stuff will need to be wired in to the various interface assets. Better use of design patterns could minimize the pain in hindsight, but fact is there is something to be said for building a scene more programatically and relying as little as possible on scene tools and scenes themselves to tie things together. My hope was to avoid refactoring at this point and instead just throw a PhotonView on my two main characters that are already wired in with data binding in DF GUI. It also demonstrates while it is quick and easy to use data binding, without some sort of abstraction from the actual characters/players themselves you get into these complex situations where a prefab isn't wired into the scene the way you need it to be and pulling out a key component in the the scene breaks how everything is wired together.

    I'm wondering if there is a way to substitute on the fly one instance of an object for another... For example if I have a 'Mage' gameobject in my scene that is wired into the GUI and other various objects it talks with that I don't want to disturb the pointers/relations that wires it all together. Could I initialize a prefab with the PhotonView and then slip that object in place of the 'Mage' gameobject in the scene that is correctly wired into everything? My struggle is that we are talking an entire spell toolbar for player character plus health, energy, buffs, level, xp, regen per second are all tied into that Mage option sitting in my scene. If I pull out the Mage object even for a split second, all the property bindings and connections are blown out and it is go to a backup time. Now if I could slip an instance of the same exact object into the place of that mage object without breaking apart all the stuff that was tied to the other instance... that would solve all my problems and likely be useful for other design problems as well.
  • DuaneDog
    Options
    So I thought of a way to go about it that might work... I'll just create a generic object with a photonview and then attach it as a child to the game object in the scene. I can then create a direct reference and use it to call whatever I need in the other scripts in the parent. That makes me wonder though... will I be able to call RPC's in the parent from a child that has the Photonview? Could I do that with a stub in which I call an RPC in my child gameobject then it just calls up to the methods in the parent?

    BTW, I still would really like to know if it would be possible to slip one object in place of another in a scene... and maintain all the references throughout the scene. That would just be pretty cool if that could be done. Most importantly at runtime.
  • DuaneDog
    Options
    Ok... So maybe I was missing something easy.

    I used this:

    PhotonView oView = gameObject.GetComponent<PhotonView> ();
    oView.ownerId = 1;

    From what it looks like in the inspector and the way it is behaving the Photon framework is ok with assigning owner id's in this manner. Let me know if there is something I'm missing. This is really all I wanted to do was assign the owner for an existing PhotonView gameobject in a scene at runtime.
  • Tobias
    Options
    Assigning the owner is not OK. It might look OK on your client but not on the others. No one else will know who you assigned as owner and unless you have been the owner all along, someone else will send updates for this GO, too.
    Never assign the ownerID.

    I got the impression that you might be someone who could get better results without using PhotonViews.
    In PUN 1.25, we added the method RaiseEvent. It's the bare-bones version of RPC. It does not need nor relate a PhotonView. You can send anything you like, basically but have program the receiving end to make good use of what you sent.
    This allows you to send data no matter which character you use, etc. Swap models, prefabs, the UI.
    Read the doc for it. Maybe this is fitting for you.