Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Photon Unity Networking

Discussion in 'Multiplayer Networking' started by tobiass, Aug 23, 2011.

  1. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    191
    Checking photonView sync options I have found that UnreliebleOnChange sync components even values wasn't changed.
    For example, Health component sync in OnPhotonSerializeView only float m_CurrentHealth value. That changes only when player received damage and according to UnreliebaleOnChange option description, that must be send only when that value has been changed, but in a fact that sync it all the time. That's why I need to use that statement

    Code (CSharp):
    1. if (stream.isWriting) {
    2.                 stream.SendNext(m_CurrentHealth);
    3.             } else {
    4.                 float tempHealth     = (float)stream.ReceiveNext();
    5.  
    6.                 if (tempHealth != m_CurrentHealth){
    7.                     SetHealthAmount (tempHealth);
    8.                 }
    9.             }
    Why that works like that? How to decrease network total sync data, using that sync only when needed?

    Another question is about master client authoritive network model (when MasterClient run all game logic over network). I didn't find a way how to use PhotonView serialisation when the other player character on master client machine could write data in OnPhotonSerializeView. Now only local (original) player instance can do it. How to implement it?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    I tested with the Boxes Demo: After the box settles down, UnreliableOnChange does not send anymore. When I send a float (and don't change it at all), it also doesn't send the value.
    Does the stream contain anything else?
     
    Last edited: Oct 19, 2016
  3. Alexsander

    Alexsander

    Joined:
    Nov 26, 2012
    Posts:
    17
    Help fix: is obsolete: `Use property with uppercase naming instead.'is obsolete: `Use property with uppercase naming instead.'

    RoomOptions roomOptions = new RoomOptions();
    roomOptions.cleanupCacheOnLeave = true;
    roomOptions.isOpen = true;
    roomOptions.isVisible = true;
    roomOptions.maxPlayers = (byte)newMaxPlayers;
    roomOptions.customRoomProperties = roomProperties;
    roomOptions.customRoomPropertiesForLobby = exposedProps;
     
  4. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    191
    Here how my gameObject inspector looks
    http://take.ms/ratN9a
    I tried to split syncing to 2 different photonview components because 2nd photonView contains components which I need to sync all the time non-stop. If I understood correctly, PhotonView will run sync if even 1 of 4 components will be changed. Is it right?
    That's why I tried to sync CharacterHealt independently. Am I wrong in my thoughts?
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @Alexsander: Replace your isOpen with IsOpen, etc.

    @novaVision: You are overcomplicating things. Use fewer scripts. Let either decide early-on if you need to send a health value. You could put a value in the stream that says "health included (or not)" or you simply send "null" instead when you don't want to send a value or nothing at all. Your reading code must cope with "is the health included or not" and you're done.
    It's easy to go wild with Unity's component approach but the more you have, the more overhead you got, too.
     
  6. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    191
    So, after your answer, did I correctly understand that
    1. there is no approach to use multiple PhotonView components on the same gameObject because of they will write the same stream?
    2. any component change in Observed Components list (like PhotonTransformView which changes almost all the time) will sync data for all the list, even if other components wasn't changed?
     
    Last edited: Oct 22, 2016
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    You should be able to use multiple PhotonView components. They don't write into the same stream but if either stream gets content, something will be sent (which initially confused you, afaik).

    I don't know what you mean by 2.
    If some component is sending updates, the PhotonView is sending it. What your components send (and what's in the stream) is on you. You define the content (by the observed scripts). This plus a little overhead per PhotonView.
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    We updated PUN and PUN+ to a new version. There are fixes for ownership transfer, the PhotonView inspector (which didn't always save changes), a fix to cleaning up networked objects when loading scenes and more.

    v1.77 (24. October 2016)
    Changed: Transfer Ownership requests are now handled a little different. For "takeover", any player's request is successful if taking from the correct, current owner OR when taking from the master client (even though the owner is technically the room). E.g.: You can takeover from actor 1, even when clients registered the object's owner as 0 (null is used for "the room", which is equivalent to "belongs to master client").
    Fixed: late joining would not be aware of ownership transfers. Now owner is matching who sends events.
    Updated: The Photon "Demo Hub" to the new uGUI. Setup demos by "Window" -> "Photon Unity Networking" -> "Configure Demos (build setup)" to get all demos in a build.
    Fixed: Chat and RPS demo when going back to the demo hub would throw errors, this is corrected now.
    Fixed: PhotonViewInspector not setting target to dirty when editing ownershipTransfer
    Changed: The "Background Thread" in PhotonHandler will only call SendAcksOnly(), if Update() didn't recently (last 200ms). This makes sure that timeouts are not affected by the background thread (which keeps the client side from timing out for a while).
    Fixed: PhotonTransformView DoDrawEstimatedPositionError was not taking in consideration parenting.
    Fixed: The RoomOptions.EmptyRoomTtl got set if only PlayerTtl was > 0. Now both values are fully independent. Note: To allow the last player to come back to a room after a disconnect, you need to define a EmptyRoomTtl. Else, the room gets cleared when the last player leaves or becomes inactive.
    Updated: Api reference for FindFriends, AuthenticationValues. It should be clearer how the userId is set (and if the playerName gets used at all).
    Fixed: An issue in NetworkingPeer.NewSceneLoaded(). It did not clean up correctly in v1.76 on loading scenes.
    Updated: PhotonNetwork.BackgroundTimeout. It's now disconnecting (not timing out) and the doc got updated for that.
     
  9. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    Please!

    Add immediatelly unity's Animation component to Photon View. I'm not using animation controller
    and I will not ever start to use it, since it is just rubbish for my use. I use Animation directly.
     
  10. JueixRocks

    JueixRocks

    Joined:
    Feb 10, 2013
    Posts:
    6
    Getting this error.


    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

    Missing method .ctor in assembly D:\Multiplayer test\Assets\Plugins\WP8\Photon3Unity3D.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
    The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in Photon3Unity3D
    Can't find custom attr constructor image: D:\Multiplayer test\Assets\Plugins\WP8\Photon3Unity3D.dll mtoken: 0x0a00000c
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @JueixRocks: Is that WP 8.0? We don't support that anymore. If it's 8.1, you might have to check which Photon .dll gets exported. The one in Assets\Plugins\Metro\ should be used for anything Windows Phone or Universal. Make sure that's the case (some configuration combinations can't be setup by us, sadly).

    @JOKaija: We are using the old Animation system in the Demo Worker. Have a look at how we do it. Sadly, we can't immediately help but will try to do this in the future.
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    We just updated PUN with a few fixes:

    v1.78 (1. November 2016)
    Fixed: NetworkingPeer ownership assignment on late join when MasterClient is involved.
    Fixed: SetTeam() (in PunTeam) now assigns the team to the target player, instead of the local one. You could use the extension method on any PhotonPlayer (not only on yours).
    Fixed: PlayerVariable.cs material assignment to take MasterClient as a special case and avoid color mixup.
     
  13. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    30
    Hey tobiass, I'm having trouble detecting when players leave so that a leave message can be published to the chat. What is the best way to go about this? I've tried the following but it has not worked

    void OnPhotonPlayerDisconnected (PhotonPlayer otherPlayer) {
    ChatChannel activeChannel = this.selectedChannel;
    if (activeChannel != null)
    {
    activeChannel.Messages.Add(string.Format("{0} left the game", otherPlayer));
    }
    }

    Any help would be appreciated!
     
  14. NebuTube

    NebuTube

    Joined:
    Oct 26, 2016
    Posts:
    7
    Someone can me say what would better for my idea.
    I am planning to do minigame like a agario(I have a good idea and already realised singleplayer)so I need server which will save all players data(stats etc). And auto creating lobby's. I'm looking on UNET or Photon. Say me what differences and how it compatible with my plane.

    PS: for example if I will do server 1000 players how many will it be cost?
     
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @commodore: What you do looks ok. You want to add the message locally? Are you sure there is a selectedChannel? Look out for errors in the console.
     
  16. MoruganKodi

    MoruganKodi

    Joined:
    Feb 11, 2015
    Posts:
    3
    Please - for the love of god, release a version of PUN with all the editor/PUN scripts precompiled as a plugin DLL (I mean everything in the PhotonNetwork folder, and also everything in the relative Editor folder), as respective *.dll and *.Editor.dll.

    PUN is unfortunately only usable if your own project is written using drop-in scripts directly in unity. But if you have a huge project with huge amounts of scripts, every change you make to your code causes unity to rebuild every single script in your assets folder, whereas having plugin assemblies do not have this problem (only the modified assembly is re-imported). As a result, the bigger a project gets, the longer unity freezes every time it has to recompile everything.

    In a huge project many developers prefer to write their game logic or libraries as plugin assemblies, and drop those assemblies into their "Plugins" folder.

    Unfortunately, none of those assemblies can reference Photon's PUN api, or the ChatAPI - because there is no way for a plugin assembly script to access a drop-in script in the Assets folder.

    I have, tried to convert PUN into a standalone set of plugin assemblies myself, but unfortunately it breaks easily with way too many dependencies on a "drop in" only design, or I end up with too many Editor dependent errors to try and fix, it immediately goes from being an "easy" to setup API, to a complete nightmare.

    My own project is now frozen due to a lack of a feature rich UNET alternative in assembly form, and my own requests to Photon (two emails in the past year) have unfortunately gone completely ignored. I do not have the time to both develop my game and an entire networking API from scratch. Which is unfortunate. If PUN included a Assembly Plugin version of all the PUN scripts by default, I would have ended up buying PUN+ ages ago. Especially due to the lack of functionality and readability within the UNET api.

    However it is unfortunate that PUN seems to consider those developing their games/projects as assembly plugins for unity as a minority that do not need to be supported in any way.

    Having 50, or 100 C# files in the unity asset folder results in extremely long built times, and unity may begin starts to have numerous errors at that point (EG: entering play mode is possible before script compilation is complete, which causes the editor to crash, one of the possibilities).

    In smaller projects PUN is fine, and easy to use - in it's current form full of drop-in scripts. But when a huge project becomes too big to be practical as drop-in scripts, PUN becomes useless without an easy way to covert it into standalone plugin our assemblies can access with full editor support. Long story short, PUN is easy to setup ONLY if your scripts are contained as assets, and not the other way around. Thus not really usable in everybody's workflow.

    This is only the 3rd time I am trying to request this, for the first time here in the Unity Forums, as my previous two email attempts gained zero response whatsoever in the past 12 months.
     
  17. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @MoruganKodi: Thanks for the input (again, I guess). I remember getting this feature request a few times (over several years). So far, it did not end up top of the list, sorry.

    Some of the background:
    When you strip all demos and the Utility Scripts, there are around 30 scripts which need compilation. We didn't consider this a relevant number of files in a bigger project. Obviously, these might add up.
    As you noticed, the downside of pre-compiling PUN is that we have to resolve a lot of compile-time options. There is a short (but potent) list of platform-dependencies and it felt like we would replace code compilation with dll-hell.
    Also, we have to figure out Editor versus Runtime class usage.

    We will try to revisit the topic but I can't promise anything.
    Who did you mail before? We reply to basically all mails, so I wonder what's up?! We are: developer@photonengine.com
     
  18. Cyance

    Cyance

    Joined:
    Jan 4, 2015
    Posts:
    50
    I am using Photon with UFPS Multiplayer kit. Have setup a NPC. But have a small issue. I have a Master Client, and 2 clients running. If i kill the NPC on one of my 2 clients you see the NPC dropping on the floor on the Master Client. Both Clients you see the NPC walking so the last animation. Something has to send from Master Client to both clients. But at the moment no idea. Haven't seen a tutorial for NPC's yet. Hopefully you can help me out. Many thanks Philip
     
  19. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @Cyance: I don't know the details of UFPS. There will be some way to let others know who died. Maybe this can be re-used for NPCs easily.
    Did you ask the UFPS guys?
    In general, I would use a RPC, to message everyone. Then you can trigger the ragdoll mode...
     
    Cyance likes this.
  20. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    Just forget this.

    I made multiplayer WORKING delta-streamer for hundreds of NPC units. No more
    full incoming buffer. No more game haltings while parsing incoming buffer.

    Just two little scripts, which holds everything.

    http://www.thecolonizers.com/forum/index.php?topic=15.0
     
  21. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    370
    EDIT1: Answer seems to be this one:
    https://doc.photonengine.com/en/realtime/current/reference/serialization-in-photon
    But not sure if struct should be handled the same way or needs per variable treatment.
    //------------------------------------------------------------------------------
    EDIT2 almost managed to convert the Structure to byteArray, will post.
    Ok I think I got close but definetly I'm going to pass an array of objects that are part of the Struct inside of the full structure.
    I think I failed to make it fully work because of the size of the byte array, it tend to crash so I made artificially big and it does not crash so much but this looks so dirty as is.
    Plus inside the Struct are a couple of strinc holding the names of the players that can be substituted easily bye the ID int and have less data up&down.
    //------------------------------------------------------------------------------
    EDIT3
    https://forum.unity3d.com/threads/c-photon-serialize-object-over-network.376093/
    that link exploains how to serialize Structures for Photon. I failed miserably and I'm passing the values individually in the array of objects of the RPC. When I've more time I'll try again.
    //------------------------------------------------------------------------------

    Hello.

    I found an issue when trying to send as a parameter in an RPC an struct that holds 10 variables inside.
    The struct is marked as [Serializable] and the types inside are stuff like int, bool string.

    Do I've to pass parameters one by one and overload the receiving method so I can repack back all the data into the the struct?


    I get this error:

    Code (CSharp):
    1. Exception: cannot serialize(): Bullet_Data
    2. ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
    3. ExitGames.Client.Photon.Protocol.SerializeObjectArray (System.IO.MemoryStream dout, System.Object[] objects, Boolean setType)
    4. ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
    5. ExitGames.Client.Photon.Protocol.SerializeObjectArray (System.IO.MemoryStream dout, System.Object[] objects, Boolean setType)
    6. ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
    7. ExitGames.Client.Photon.Protocol.SerializeParameterTable (System.IO.MemoryStream memStream, System.Collections.Generic.Dictionary`2 parameters)
    8. ExitGames.Client.Photon.Protocol.SerializeOperationRequest (System.IO.MemoryStream memStream, Byte operationCode, System.Collections.Generic.Dictionary`2 parameters, Boolean setType)
    9. ExitGames.Client.Photon.EnetPeer.SerializeOperationToMessage (Byte opc, System.Collections.Generic.Dictionary`2 parameters, EgMessageType messageType, Boolean encrypt)
    10. ExitGames.Client.Photon.EnetPeer.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypt, EgMessageType messageType)
    11. ExitGames.Client.Photon.PeerBase.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypted)
    12. ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Generic.Dictionary`2 customOpParameters, Boolean sendReliable, Byte channelId, Boolean encrypt)
    13. ExitGames.Client.Photon.LoadbalancingPeer.OpRaiseEvent (Byte eventCode, System.Object customEventContent, Boolean sendReliable, .RaiseEventOptions raiseEventOptions) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:627)
    14. NetworkingPeer.OpRaiseEvent (Byte eventCode, System.Object customEventContent, Boolean sendReliable, .RaiseEventOptions raiseEventOptions) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1091)
    15. NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, Boolean encrypt, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3211)
    16. PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, Boolean encrypt, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2724)
    17. PhotonView.RpcSecure (System.String methodName, PhotonTargets target, Boolean encrypt, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:595)
     
    Last edited: Nov 14, 2016
  22. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
  23. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    370
    Thank U tobiass, Yes I was suspecting so, what I did in the end was to send a few components of the Struct, so this way I've the code a bit divided betwen ofline&online.

    I send only very specific ones such as Hit-energy and the Players Id involved in this event, this way I can recreate remaining values of the struct using photonID, by accesing to that specific players customProperties such Team, Tier..., or name, these variables are "regenerated" at every clients side.

    Initially I had just an RPC that shared the event of shooting the bullet, but there is always some lag so not in all clients will see the same shot hit the same point and so calculate same damage.

    What I've done is that the bullet has an ownership Id, when its 0 (owned by player of that client) it does calculate the damage and syncs it via RPC with other players that will calculate the remaining armor by reducing the hit damage that is passed via RPC. They all are sync nicely now. The damage of a bullet that is not owned by the curret client is not calculated locally, only by the data received from the RPC.

    The visuals could be offsinc, thinking of sending an impact point RPC but for now I'm leaving it as is.
     
    tobiass likes this.
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    We just released a new version. Make sure to look out for the new regions! :)

    v1.79 (18. November 2016)

    Changed: PUN will no longer aggregate the data from ALL objects in a group into ONE message. Instead, a maximum of 10 objects will be sent together. The idea is to avoid huge messages, which need fragmentation. Fragmentation needs to be avoided, because fragments are always reliable (and you basically lose "unreliable" updates when you send too much). There is a new variable for this: NetworkingPeer.ObjectsInOneUpdate.
    Changed: As we send max 10 gameobject-updates in one message (by default), we can use a byte as type for their ID (instead of short). This minimally saves data but makes this PUN incompatible with older builds. We separate PUN versions for you so there won't be a clash. PhotonNetwork.versionPUN is inserted into your Game Version to separate players.
    Updated: PunTeams to keep PlayerPerTeams Listing up to date.
    Updated: PlayerRoomIndexing improved consistency across various network contexts.
    Fixed: SocketWebTcp for WebGL was time scale dependant and would stop receiving events when Time.TimeScale = 0.
    Updated: DemoChat UI reworked to match demo Hub look and feel.
    Updated: DemoHub pixel Perfect Canvas fix.
    Added: Two more regions: Korea, Seoul (kr) and India, Chennai (in). If you're using the hosting option "Best Region", you may want to update the configuration in your PhotonServerSettings file.
     
  25. MerhatPandzharov

    MerhatPandzharov

    Joined:
    Aug 29, 2015
    Posts:
    80
    @tobiass I am building game that i am expecting around 200 CCU but should i pay 95$ montly for 500 ccu or 95$ one time because i cannot afford 95$ monthly but i can afford for 100 CCU so i don't know what to do :(
     
  26. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    370
    I would pay the 100CCU, If you trully are getting 200CCU the system will allow you for a short period that overload of users. If you trully get that 200CCU you should make your business model be able to fit that 95$ monthly cost.
     
    Last edited: Nov 19, 2016
  27. MerhatPandzharov

    MerhatPandzharov

    Joined:
    Aug 29, 2015
    Posts:
    80
    Yes if it will enable for short time to handle the needed requests i will update to highe ccu but if after few months it gets mostly 100 ccu can i downgrade it to 100 ccu for free or i must buy it again ?
     
  28. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    Of course you can downgrade your subscription, too. You're never stuck with the highest-ever CCU count. Just make sure you cover the highest CCU in a month and you're fine.
    The 100 CCU from a one-time purchase will be yours for the entire time, no matter what else you book.
     
  29. MerhatPandzharov

    MerhatPandzharov

    Joined:
    Aug 29, 2015
    Posts:
    80
    Ok i have a question i am making multiplayer quiz game like there are 2-4 people in room and every one have 20 seconds to answer a question. I am making the game with photon one person is listening to all the events send by others and responding them with another event something like 'host' but i don't know is it a good idea to make it that way.
     
  30. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    370
    the only host here is the photon server that is located in EU, USA etc.. all the people in your game are CLIENTS, yes there is a Master client but that is only a feature of a CLIENT not a host or anything. The client "feature" can be passed to others, may be you can play with that if you need any specific action to be done by the owner of the game, may be you could pass the ownership to the one that is withing the time windows to answer.
     
  31. MerhatPandzharov

    MerhatPandzharov

    Joined:
    Aug 29, 2015
    Posts:
    80
    I know that there is no other host than Photon but how i can make that 4 people in room see the same quiz question i made it now with photon events and event codes but i don't know if it is good.
     
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @MerhatPandzharov: With a 4 player game, having a "host" is usually OK and a simple way to handle things. You should try to handle what happens, when that host leaves (for whatever reason).

    In Photon, there is no real hosting of games in-Unity. As "replacement", we have a "Master Client". It's a client like any other, actually, but it's singled out so it could make decisions which only one player should do (start a match, when enough players are there, etc).

    Edit: You might want to send the questions a moment before the round starts. So everyone can start at the same ServerTimestamp. After a round, allow some extra time for replies to arrive (they might be slightly delayed by lag, etc).
     
  33. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    If you like to use structures, you may like do that like I:

    Code (CSharp):
    1.  
    2. [Serializable]
    3. public class _structured_data
    4. {
    5.     public string data1;
    6.     public string data2;
    7. }
    8.  
    9. public _structured_data structured_data;
    10.  
    First of all. Use unitys json to collect structure to one string:

    string json = JsonUtility.ToJson(structured_data);

    and vice versa:

    structured_data = JsonUtility.FromJson<_structured_data>(json);

    Then you can send/receive it as it is (json, poor) or base64 encoded string (poor, one character = 2 bytes) OR byte coded.

    Using this simple routine will return string as "bytes"

    Code (CSharp):
    1.  
    2. getBytes(string s)
    3.     {
    4.         if (s != null)
    5.         {
    6.             List<byte> bytes = new List<byte>();
    7.             foreach (char ch in s.ToCharArray())
    8.             {
    9.                 bytes.Add(Convert.ToByte(ch));
    10.             }
    11.             return bytes.ToArray();
    12.         }
    13.         return null;
    14.     }
    Now you can send easily ie. via events:

    PhotonNetwork.RaiseEvent(69, getBytes(json), true, RaiseEventOptions.Default);

    There is a routine to convert bytes back to string from received bytes:

    Code (CSharp):
    1.  
    2. string getString(byte[] bytes)
    3.     {
    4.         if (bytes != null)
    5.         {
    6.             string ret = string.Empty;
    7.             foreach (byte b in bytes)
    8.             {
    9.                 ret += (char)b;
    10.             }
    11.             return ret;
    12.         }
    13.         return ("");
    14.     }
    15.  
    Just look idea from my burster code at:

    http://www.thecolonizers.com/forum/index.php?topic=15.0
     
    Last edited: Dec 1, 2016
  34. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    Hello I got rejected several times from Apple with this message:

    We discovered one or more bugs in your app when reviewed on iPad and iPhone running iOS 10.1.1 on Wi-Fi connected to an IPv6 network.
    Specifically, the app never successfully connects to the server.


    I used version PUN+ v1.76
    I want to know if I upgrade to lastest version v1.79 is this is going to be solved?
    Also, do you know if I will need to recompile Android and Windows Store games with newest version? Or version v1.76 is compatible with v1.79 ?
     
  35. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    113
    Hey Tobiass,

    Any thoughts on this thread? Thanks in advance!

    -ss
     
  36. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    @andrescavallin: It is very likely a problem on their end, testing the app. We made sure everything is correct and covering IPv6 as long as Nat64/DNS64 is available. Without that, it won't work but almost no app will under those conditions. And: They never asked for pure ipv6 support to begin with (so why test those).
    We summarized how you make sure your app is correct and how to reply to them to ask for a re-test or approval:
    http://forum.photonengine.com/discussion/7702/ipv6-for-unity-ios-exports
    You definitely need to test once with their guide, so you can tell them it works and that you tested.
    If they want to get into a call, we would be happy to participate.
     
  37. lich2king

    lich2king

    Joined:
    Nov 7, 2012
    Posts:
    6
    Hello,
    I'm using PUN cloud (with best region in settings) v1.79
    Unity 5.4.3f1 (64-bit)
    And I got rejected by apple for not connecting in IPv6 networks.
    Any ideas ?

    Maybe Unity 5.4 doesn't work with ipv6, but how about 5.5 ?

    Thank you.
     
    Last edited: Dec 12, 2016
  38. dylanh7244

    dylanh7244

    Joined:
    Jan 12, 2016
    Posts:
    395
    fyi, Photon charges +$100/mo for their chat -___- other services (like UNET) include this for free.

    EDIT: Thunder, however, claims to be 1/5 of UNET's prices, though, with 99% of the same code!!
     
    Last edited: Dec 24, 2016
  39. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    I read in some post that 5.5 does OK. But we know that it's not always just the version of Unity, which makes the difference in getting accepted. As long as you tested with Apple's guide, you should get accepted. Many developers had to appeal the rejection by Apple (pointing out that they did test properly) and did get accepted a while later. Often without changes.
    Please do test and talk to Apple about the rejection.

    @dylanh7244: uNet has chat between clients which are connected directly (or via the relay). Photon has servers for clients who never have to directly connect. This makes sense when your players should be able to chat independent from the room/game they are playing.
     
    dylanh7244 likes this.
  40. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    We just released a new update for PUN in the Asset Store. Various smaller fixes and changes:

    v1.80 (15. December 2016)

    Fixed: PhotonTransformView first take routine to take in consideration what to update instead of forcing position, rotation scale no matter what.
    Updated: PlayerRoomIndexing.cs to account for potential race conditions when masterClient is transfered and new player joins. SanitizeIndexing() is now in place.
    Fixed: Fix ownership management for scene objects when MasterCLient is/was changed.
    Updated: Chat demo, with new Friend Status update and message implementation available in the Interface as a friends' List.
    Added: "Best Region" support for WebGL exports (uses http to measure roundtrip times). Works preliminary but requires a server-side fix for CORS, coming early next year. When your game is hosted via http, this should be fine.
    Fixed: JoinRandomRoom() will now correctly send ExpectedUsers to the Game Server (if any were set in the RoomOptions). This fixes issues when you wanted to reserve slots in a room for other players.
    Added: A null-reference check in FindGameObjectsWithComponent(), which could fail in rare cases otherwise.
    Changed: Setting RunInBackground is now done in the PhotonSettings file. It's enabled by default but in a few exports, this could lead to issues.
    Added: The internal "AuthEvent". This event by the server can now update the client's token anytime (before that expires). Good for longer play sessions.
    Removed: Surplus debug log output.
    Changed: Public variable- and property-naming to PascalCase (beginning with an uppercase character) in RoomInfo, Room and PhotonPlayer class. The old naming is still available but attributed as Obsolete, so you should update asap. Sadly, this is extra work for everyone but we want to make the API more stringent.
    Changed: The PhotonPlayer.name is now .NickName to make it more obvious that this is not the user's ID (and might be changed at will).
    Removed: Obsolete PhotonView.observed. Since a while, each PhotonView has a list of observed components instead. If you have a very old (!) project, check your PhotonViews and make sure they still observe the scripts you meant to observe. Newer projects won't be affected.
     
  41. Afif-Faris

    Afif-Faris

    Joined:
    Oct 11, 2013
    Posts:
    16
    i have question about photon unity3d SDK v4.1.1.6, OpJoin method don't have any actorId parameter like it was, i want to rejoin to a room using the same player id after disconnected for whatever reason.

    How to do that now? i tried OpReJoin room but cant connect to the room and get room not exist response, even though the other players are still playing in that room.

    please help me, this problem drive me nuts.
     
  42. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    To get this working, use OpReJoinRoom. You need to make sure that you're using some UserID per client/user (you don't need a Custom Authentication server but you have to use some made up userID per client or per user and AuthValues) and you need to create rooms with the RoomOptions.CheckUserOnJoin = true.
    We don't support the rejoin with just the ActorNumber anymore. It was too error-prone.


    This thread is about PUN and the support for the LoadBalancing API (Unity Client SDK from our webpage) is in our forum. If this reply doesn't help, please head over to: http://forum.photonengine.com/categories/dotnet
     
  43. cjackcandy

    cjackcandy

    Joined:
    Sep 8, 2013
    Posts:
    5
    I just downloaded version 1.80 and it appears that tpEffects.cs is using the removed PhotonView.observed variable. Do you have a suggestion for how we can fix or work around this?
     
  44. cjackcandy

    cjackcandy

    Joined:
    Sep 8, 2013
    Posts:
    5
    Please ignore my last post - the affected script was from a different package - apologies for the spam post.
     
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    The PhotonView has a List<Component> ObservedComponents. It may be null, one entry or it may even have more than one entry. You can iterate over it to check what is observed and you can add entries. If the list is null, just create it.
     
    seansteezy likes this.
  46. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    4,544
    Our company DarkTonic uses Photon and loves it. We are proud to announce that Master Audio Multiplayer is now live on the Asset Store! It's the ONLY multiplayer audio solution for Unity - yes, even the big players such as Fabric, WWise and FMod do not offer this. No RPC's to write. More info here, and there is upgrade pricing for existing Master Audio users. Currently requires Photon, UNET compatibility coming soon. It uses clever code to find the nearest PhotonView and send 1 of 93 RPC's over the wire, then navigate down to the correct game object and call Master Audio API. Also includes a dead simple "Multiplayer Broadcast" checkbox on our included Master Audio event-based scripts.

    Spread the word!
     
    tobiass likes this.
  47. dylanh7244

    dylanh7244

    Joined:
    Jan 12, 2016
    Posts:
    395
    The other day I've been learning about Photon Thunder. This is same crazy stuff -- using 99% of the same UNET HLAPI code with claims of 1/5 the price of UNET~ The main reason we went with UNET in the 1st place was because of price. Now the main reason we don't try Photon dedicated server is not only price, but too much code to change.

    But Photon Thunder ..... punch through and host migration working with claims of 1/5 the cost of UNET? Yes please. Host migration alone is something that Unity has claimed to have for so long but has been confirmed broken since June.
     
  48. kashiftasneem

    kashiftasneem

    Joined:
    Aug 24, 2012
    Posts:
    12
    Hello guys. I am new to photon and have released game on Android using PUN version 1.78. Now I updated the SDK to version 1.80. But users from different versions are not able to play with each other. Is this normal? I want users from all versions to play with each other.
     
  49. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,881
    Yes, that happens by design.
    Only this way, we can make sure that changes in PUN don't break older clients. You should encourage players to update their clients.
    You could change the PhotonNetworking.versionPUN string to match that of 1.78 (and use the same GameVersion string for ConnectUsingSettings()). If both match the older version, the clients would be matched but we don't guarantee compatibility (and can't support this case at all).
     
  50. carrotstien

    carrotstien

    Joined:
    Jun 8, 2016
    Posts:
    4
    Hi Tobiass, not sure if this is the right place to ask. We are currently looking for network solutions for cross console support. The game requires latency to be minimized, so p2p if possible (vs player-server-player). It looked like Bolt might have what we need, but I hear the it isn't supported on the PS4. PUN seems to be what we need, but I can't tell if it provides p2p functionality, or if it locks into the p-s-p connection. If you have a moment to discuss, I can be reached at carrotstien [at] gmail [dot] com.