Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Photon Unity Networking

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

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    490
    I looked at PrefabPool. But this requires the use of prefabs being in a resource folder?
    Code (csharp):
    1. PhotonNetwork.PrefabPool.Instantiate
    The reason I don't want to use a resource folder is cause I don't want to load enemies into a scene that isn't currently for that scene.

    So i'll have to make my own pool then with Manual instantiate
    https://doc.photonengine.com/en-us/pun/current/manuals-and-demos/instantiation

    Idk is it possible to take a list of prefabs and load them into resources so that resource string look up works? I'm gonna see if Unity has something like that.

    Maybe I'm wrong as to how resources work. Does everything in all resource folders get loaded into memory when a scene loads? Even before you do any instantiating from resources?

    Even if it doesn't load all resources into memory. What if I have 50 prefabs for 50 different scenes. That's 2500 objects that resources has to search through when instantiating from resources. Unless photon networking.instantiate supports resources relative link for it's resource string agrument?

    Sorry for having a few questions @tobiass . Really need answers to this. Getting pretty deep into my project now
     
    Last edited: Aug 7, 2017
  2. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    207
    Hi,

    Have you checked my demo project on Pooling with Photon? it shows how to do this and indeed how you can totally choose the way to use prefabs resources using pool systems off the shelves or your own way.

    https://github.com/jeanfabre/Exitga...s/PoolManager/Scripts/PunPoolManagerBridge.cs


    Resources are only loaded when you say so, so you are responsible on how to use theses resources and no they will not be loaded with levels at all, they are only loaded on demand via your own logic ( or photon's logic in the case of network instantiation when not using pooling systems).

    Let me know if you need more help on this.

    Bye,

    Jean
     
  3. Nikolasio

    Nikolasio

    Joined:
    Dec 6, 2014
    Posts:
    29
    Hi,

    I'm looking for a way to instantiate a player in a room (left side screen for the player owner) and displaying this same player on another position (right side screen) for the other player to see.

    So basically, in a 2 player game, when you enter a room, your player is always displayed on the left side of the screen.

    Is this even possible?
     
  4. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    17
    I am running on an Android device as master and also on editor on Mac OSX
    as client with PhotonNetwork.automaticallySyncScene = true;

    When I call PhotonNetwork.LoadLevel(2) it always takes over 127 seconds
    for the level to load on the device and then instantly on the editor?

    The loaded level is nothing more than a blank scene with a single cube in it.

    If I run the other way round, master on editor on Mac OSX and client on
    the device PhotonNetwork.LoadLevel(2) load the scene in under 3 seconds
    but does not load on the android device.

    I can seem to see why this is so....help anyone?

    Thanks
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @Nikolasio: Everything is possible. It's just some coding. How about turning around the cam? It makes most sense, I would guess. Then the scene is consistent. Alternatively you can try to write the OnPhotonSerializeView() in a way that flips the sides.

    @piginhat: If the actual loading is taking so long, it's not a topic for this chat but likely a bug. Afaik, the Basic Tutorial is loading scenes. Did you try implementing that?
     
  6. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    223
    @piginhat: If the actual loading is taking so long, it's not a topic for this chat but likely a bug. Afaik, the Basic Tutorial is loading scenes. Did you try implementing that?[/QUOTE]

    Currently in chat with Photonians.

    But to expand my model scene loads OK in an AR app, a basic 2 scene app and works OK. It is only when I add Photon to load the scene the delay appears.

    I have tested the demo app and loads perfect. Add my model...long long delay. But like I say, the model works perfectly OK in my other non Photon apps.
     
  7. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    260
    I'm getting warning:

    OnLevelWasLoaded was found on PhotonHandler
    This message has been deprecated and will be removed in a later version of Unity.
    Add a delegate to SceneManager.sceneLoaded instead to get notifications after scene loading has completed
     
  8. Twitwi

    Twitwi

    Joined:
    Apr 11, 2012
    Posts:
    19
  9. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    223
    Currently in chat with Photonians.

    But to expand my model scene loads OK in an AR app, a basic 2 scene app and works OK. It is only when I add Photon to load the scene the delay appears.

    I have tested the demo app and loads perfect. Add my model...long long delay. But like I say, the model works perfectly OK in my other non Photon apps.[/QUOTE]

    Turns out (my bad) I had the model in question in the Resources folder where it should not have been. Thanks to Photon support for pointing this out.

    Problem solved
     
  10. Pettas

    Pettas

    Joined:
    Oct 21, 2015
    Posts:
    30
    Hello, this system is also nin-Authoritative, like Unity? What happens with the events (e.g. when a new player joins?)
     
  11. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    490
    https://www.photonengine.com/en-US/Chat

    Does this chat service run separately from the normal photon multiplayer networking?
    Can it handle 1000 players.
    So hard to explain lol.

    another way to word it.
    is the chat networking rooms completely separate networking from the game play networking.
    I'm making a MMO with photon networking but its actually instances with just a few people. so not a real MMO but I need the chat to be like a MMO.
    so I need a chat system that will network everyone to a single chat.
     
  12. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    490
    Is there a common bug with Photon networking where eventually a GameObject with a PhotonView component attached to it gets destroyed? I've noticed my character eventually gets destroyed after being idle for a while. I don't even have anything in my game logic that does that I don't think. I;ve noticed this over the last few months with a few different games I've been making too.

    According to my log it seems they just get destroyed when the server messes up?
    Or my internet messes up either one. Idk which.
    I know I need to kick the player out of the game or do something while he is having connection issues. Idk why it would destroy everything though?
    Is it possible to get it to stop destroying stuff?
    Or do i have to reload everything if the player lags out?


    Code (csharp):
    1. OnStatusChanged: DisconnectByServer current State: Joined
    Code (csharp):
    1. OnStatusChanged: Disconnect current State: Disconnecting
    Code (csharp):
    1. Network destroy Instantiated GO: Shadowing

    Code (csharp):
    1.  
    2. OnStatusChanged: DisconnectByServer current State: Joined
    3. UnityEngine.Debug:Log(Object)
    4. NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1922)
    5. ExitGames.Client.Photon.EnetPeer:ExecuteCommand(NCommand)
    6. ExitGames.Client.Photon.<>c__DisplayClass57_0:<ReceiveIncomingCommands>b__0()
    7. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    8. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    9. PhotonHandler:Update() (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)
    10.  

    Code (csharp):
    1.  
    2. OnStatusChanged: Disconnect current State: Disconnecting
    3. UnityEngine.Debug:Log(Object)
    4. NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1922)
    5. ExitGames.Client.Photon.<>c__DisplayClass148_0:<EnqueueStatusCallback>b__0()
    6. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    7. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    8. PhotonHandler:Update() (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)
    9.  

    Code (csharp):
    1.  
    2. Network destroy Instantiated GO: Shadowing
    3. UnityEngine.Debug:Log(Object)
    4. NetworkingPeer:RemoveInstantiatedGO(GameObject, Boolean) (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3270)
    5. NetworkingPeer:LocalCleanupAnythingInstantiated(Boolean) (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1115)
    6. NetworkingPeer:LeftRoomCleanup() (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1080)
    7. NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2023)
    8. ExitGames.Client.Photon.<>c__DisplayClass148_0:<EnqueueStatusCallback>b__0()
    9. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    10. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    11. PhotonHandler:Update() (at Assets/Scripts/Third Party Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)
    12.  
     
    Last edited: Aug 27, 2017
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    We just updated PUN to v1.86. It's a smaller update but contains important changes for console export and Unity 2017 support:

    v1.86 (30. August 2017)

    Fixed: The fallback thread implementation to always call SendAcksOnly, as long as isMessageQueueRunning is false. This keeps connections from timing out by sending ACKs and Pings as needed.
    Fixed: Compatibility with Unity 2017.
    Changed: In the PhotonServerSettings, you can now select any of the implemented Transport Protocols for Photon: UDP, TCP and WebSockets. WebGL will always use WebSockets and Xbox One has it available, too. If you want to use it on other platforms, you have to set the define WEBSOCKET and make sure the websocket dll exports to the target platform.
    Note: Check your PhotonServerSettings to make sure the (Transport) Protocol setting is valid after updating.
    Note: A few files were moved within the Unity project. The Editor should figure out they are moved and updated. If it logs errors about duplicate definitions, look up the location of the class in this package and remove the other.
    Updated: PUN to no longer uses obsolete enum values of the Photon library (dll).
    Added: tvOS to the meta settings of Assets\Plugins\Photon3Unity3d.dll.
    Updated: Photon3Unity3d.dll to v4.1.1.15. See Assets\Plugins\release_history.txt for details.
    Xbox One:
    Changed: This PUN version only allows WSS communication on Xbox One. A thin native library is used as wrapper for the platform implementation of WSS.
    Updated: The warnings/errors for UNITY_XBOXONE for the cases: "No authentication value", "Wrong authentication type", "XSTS token not set for authentication" and "Not using WSS".
     
  14. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    207
    Hi,

    yes, they run on their own, and has a different dashboard, app Id and you pay separately.

    chat sdk will handle 1000 players fine, because it's a different networking structure.

    so yes, there is not "room" in chat, only channels, so if you run both PUN and chat, it's not because you join a room in PUN that the chat sdk will be aware of it, it will not, it's completely separate.

    in your case, yes using chat will be a good thing because all players will be able to communicate even if they are not inside the same pun room.

    On that matter, I started a while a go a PunChatClientBroker class that will connect and handle both connection with one unified API, maybe that could be interesting for your project? https://github.com/jeanfabre/Exitgames--Custom--Samples_U4

    Bye,

    Jean
     
  15. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    207
    Hi,

    I am not aware of any issues with networked gameobject being destroyed out of the blue, given your logs, you got disconnected from the server and so yes in this case network gameobjects are destroyed.

    to check the cloud status, go to this page, if you are in doubt, it will tell you if the cloud is up or down.

    https://www.photonengine.com/status

    if you don't want this to happen, you can set photon to not destroy automatically and you will get a callback which will let you decide what to do with your networked gameobjects.

    more infos here:
    https://doc-api.photonengine.com/en...etwork.html#a6c6fb3cd57d7e2a13d1fc354db0c1fd7

    Bye,

    Jean
     
  16. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    490
    @Jean-Fabre Thanks a bunch man. Thats all I needed to know.
     
  17. sonnyboy

    sonnyboy

    Joined:
    Oct 25, 2015
    Posts:
    8
    Hi,
    There are still a lot of errors coming up directly inside your classes bound to 2017.1 for your 1.86 version. I have to find all #if UNITY_5 definitions and swap them with 2017 and there are a lot of them there. Are you sure you have opened the latest Photon with Unity 2017?

    Thanks
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @sonnyboy: I personally didn't but my colleagues checked Unity 2017.1 before we released 1.86.
    Can you name a few places and which platform you selected? And are you using 2017.1 beta, the release or a updated version?
     
  19. sonnyboy

    sonnyboy

    Joined:
    Oct 25, 2015
    Posts:
    8
    @tobiass

    I am using 2017.1.0p2. I created a fresh project and import your Photon PUN+ package from Unity AssetStore.

    First Problem :
    Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs(408,63): error CS0104: `Hashtable' is an ambiguous reference between `System.Collections.Hashtable' and `ExitGames.Client.Photon.Hashtable'
    As example bound to line :
    #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5 || UNITY_5_0 || UNITY_5_1 || UNITY_6
    using UnityEngine;
    using Hashtable = ExitGames.Client.Photon.Hashtable;
    using SupportClassPun = ExitGames.Client.Photon.SupportClass;
    #endif

    Second problem :
    Assets/Photon Unity Networking/Demos/DemoHub/Editor/PunStartup.cs(76,9): error CS0433: The imported type `UnityEditor.SceneManagement.EditorSceneManager' is defined multiple times

    Third Problem :
    Assets/Photon Unity Networking/Editor/PhotonNetwork/Views/PhotonAnimatorViewEditor.cs(82,16): error CS1061: Type `PhotonAnimatorViewEditor' does not contain a definition for `m_Controller' and no extension method `m_Controller' of type `PhotonAnimatorViewEditor' could be found. Are you missing an assembly reference?

    I have cleaned all those problems by simply swapping Unity_5 with Unity_2017 in all project as a quick solution but I think I have made mistakes on some necessary defining of version so the project failed to continue on play.

    Maybe you have cleaned the problems on free version but not on PUN+?

    Thanks
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @sonnyboy: That file is outdated or not updated correctly. We no longer have a single "UNITY_6" define in our code. I also can't find it in PUN+ when I download it from the store. Please make sure the update went well.
     
  21. sonnyboy

    sonnyboy

    Joined:
    Oct 25, 2015
    Posts:
    8
    Hi @tobiass
    Somehow Asset Store was showing the package updated but it was not. I erasedthe old version from local drive and it downloaded the right version. Sorry for the trouble and thanks for your help!
     
  22. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @sonnyboy: Ah, that's confusing of Unity! Well, glad you found it. You're welcome - have fun!
     
  23. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    @tobiass I have taken a look at the network culling demo shown here https://doc.photonengine.com/en/pun/current/manuals-and-demos/culling-demo

    Is it meant to work or just show an example of a bit of an approach to the problem? The reason I ask is that it seems to work a bit, but not very well. I end up with the Kyle characters standing next to each other on one instance and in a totally different place, often far apart in another instance. I would have expected that if the players were meant to be close to each other, then they really would be very much in sync.
     
    Last edited: Sep 11, 2017
    Munchy2007 likes this.
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @Baraff: I would expect the demo to work but I didn't test this one myself. We will have another look and check what's happening.
     
    Munchy2007 likes this.
  25. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    Thanks @tobiass, that would be great to know that I am at least looking at a working example. This example would need changing to incorporate view culling for me, but not much point starting if it is currently broken code.
    FYI, I have been using 2017.1.0p5 based Unity's, in case that matters.
     
  26. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @Baraff: It might matter, yes. We will have a look at Thursday and get back to you here.
    You are using PUN v1.86, I assume?
     
  27. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    Thanks for the prompt! I totally thought I was already on the latest version. As it turned out, I was still on v1.85. So I updated and now it seems to work fine. So I would say to anyone who has this problem, if you are on v1.85, this demo is broken, but worked fine with v1.86 on my 5 minutes of kyle running around test. On v1.86 it was obvious it was not working very quickly.
     
  28. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    @tobiass It seems I may have spoken too soon. I had forgotten that last time I looked at this I had removed the Network Culling Handler to to make sure the RPG demo was working at all. So my comment before was of course looking at the standard RPG demo which of course works. Tried it again with the component added and while it seemed better it was still possible to create a situation like this pretty easily. As you can see they are not in sync here. So it it seems to be broken still. In the image on the left the Kyle on right is controlled in this instance and can be seen next to the other Kyle, but in the image on the right, that Kyle is offscreen.

    upload_2017-9-13_6-9-30.png
     
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    Hmm. The subscribed cells are identical, which is good. We'll have to debug.
    Thanks for the updated input!
     
  30. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @Baraff: We took a look and can confirm the demo was broken in v1.85 but works in v1.86.
    I'm not sure of we even noticed it now works again (as there is no note in the changelog).

    To anyone using Unity 2017: It seems there are potential issues with updating projects and importing packages. We checked compatibility with 2017 (but not the beta) so PUN works. If you run into issues, try importing into a new, empty project. In worst case, copy the files from there to your project in the explorer/finder.
     
  31. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    @tobiass The test above was performed on 1.86 and it was still broken as you can see in the image I posted.
    I noticed that there was an update pushed last night called 1.86.1. There are no release notes for what was changed or fixed or patched but this update to 1.86.1 seems to fix the problem as far as I can tell from testing today.
     
  32. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    490
    Is there anything that Exit games makes that allows me to do a full serverside MMO using linux?
    I think there should be a bit of a change with how you guys advertise your server types. Its a bit confusing.
     
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    That would be astonishing, as the .1 update is minimal and only relevant for some console exports. Unless you tested on those, there is no change that affects this demo but maybe the new import made the difference.
    Anyhow: Glad it's now working.

    @Shadowing: Photon Server does not run on Linux, so that's not a match. Otherwise, it would be a good basis for your project. It's in use by Albion Online, e.g., which has a lot of action.
    If you are OK to run Unity headless on Linux for an MMO, then you can use Bolt but we would guess it's too expensive to do (your game and Unity have to run really performant for that to be feasible).

    We're also not entirely happy with the way the products are explained. Some of this is .. difficult and there are always pro's and con's. Will have a look at it.
     
  34. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    @tobiass Ah well just a Unity import hiccup then I guess. I did try deleting and reimporting just to be sure which just makes the confusion even worse when it still does not work. Anyway it seemed to work OK with the update, so go figure.

    Next item to address will be the random server disconnects which I have not even begun to look at yet. If you have any tips on possible things to look at, that would be appreciated. Possibly timeout related but that's just based on what I thought I saw in a log at some point while working on other things.
     
    Last edited: Sep 19, 2017
  35. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,882
    @Baraff: Good the initial issue is gone. If you have disconnects, that might be related to debugging? When you pause all threads, that may happen?!
     
  36. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    203
    I do see the debugging ones and they make sense. The random disconnects I am talking about however, just happen randomly. I have even seen it happen within the first few seconds. I can also complete a number of games that last around 10 minutes and not see the problem. Random events like this are not fun to find but any suggestions you may have would be helpful.