Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Photon Unity Networking

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

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    Fusion should not require the definitions via Editor, no.
    When there is a public beta (no ETA yet), we should figure out how nice it plays with your personal framework.
     
  2. miracletechteam1

    miracletechteam1

    Joined:
    Sep 18, 2019
    Posts:
    11
    Hi Tobiass, is there any link to get Old PUN?
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    No, we don't distribute old versions. If you want to let us know about your case, mail us: developer@exitgames.com.
     
  4. exltus

    exltus

    Joined:
    Oct 10, 2015
    Posts:
    58
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    RPCs are not serialized to only consist of a byte[], so at the moment, ByteArraySlice can't be used for them.
    Use RaiseEvent, send only a byte[] as content and enable the usage of ByteArraySlice, so the receiver will also use it. This is currently the best option.
     
  6. exltus

    exltus

    Joined:
    Oct 10, 2015
    Posts:
    58
    Ok, can you tell me if you are thinking about adding support for this in future?
     
  7. exltus

    exltus

    Joined:
    Oct 10, 2015
    Posts:
    58
    And what about OnSerializeView - is somehow possible to avoid allocations?
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    At the moment, this is not possible or planned, sorry.
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    We just released a new version of PUN 2. The big change is an overhaul of the PhotonView.ViewID assignment, Owner and Controller caching. Let us know if this causes issues in any projects.

    v2.28 (23. February 2021)
    Changed: PhotonView code to cache Owner and Controller, as well as storing the sceneViewId for objects which load with the scene. This is a bigger change and complex, so it may break some projects, despite the testing! Mail us, if you run into issues with ViewIDs, Ownership, etc: developer@photonengine.com.
    Added: DisconnectCause DnsExceptionOnConnect and ServerAddressInvalid (which might be renamed).
    Changed: Inspector to trim the values of AppId fields.
    Fixed: Likely fixes issue with Resources.Load failing to find prefabs in latest Unity versions. This is more of a workaround for Unity problems/changes.
    Changed: The re-usable list of PhotonViews in RemoveInstantiatedGO() is now cleared when it's no longer needed to avoid lingering PhotonView references (memory leaking).
    Added: OfflineMode to StaticReset(). So fast play mode (without domain reload) will not keep the client in offline mode.
    Changed: PhotonNetwork.Server for offline mode. It will now report the GameServer when an offlineroom is existing.
    Added: In OfflineMode, PhotonNetwork.LeaveRoom() will now also call the OnConnectedToMaster() callback. As the OfflineMode changes values immediately, the timing of callbacks might be slightly different than in online mode. Joining a room offline is instantaneous.
    Updated: Library to v4.1.5.0. which includes using the new Native Encryptor API (v2), a fix for NonAllocDictionary.Remove() and new StatusCode entries for DNS and IP issues.
     
  10. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    91
    Hello, Tobiass!

    I would like to run dedicated server application for realtime multiplayer game (console unity executable for windows) in Photon Cloud.
    Is it possible or only way is to run self-hosted photon server?
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    You want to run an instance per Photon room?
    It's not possible to host Unity (headless) instances in the Photon Cloud. Multiplay would be a suitable service for that.
     
  12. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    91
    Yes, I want run 1 instance of console application per room. Instance will be authoritative server - all others just clients.

    What do you mean under "Multiplay service"?
    I did not find in "https://dashboard.photonengine.com/en-US/" anything about running executable instances in the Photon Cloud.

    Could you please give me link to read about how to upload and run console application (that acts as dedicated server) in Photon Cloud?

    I can done it via self-hosted Photon Server, but this is not an option for scale and low-ping (I need servers in each region).

    Thank you!
     
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    We do not run executables in the Photon Cloud. Unity Multiplay does.
     
  14. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    There is a known issue in PUN 2.28 and 2.281. in which scene objects won't always initialize their ViewID, Owner, etc before OnEnable() is called on some other scripts on the same object.

    The workaround is to set a negative value for Photon.Pun.PhotonView in the Script Execution Order!

    We will work on a better solution.
     
    Munchy2007 likes this.
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    We released updates to fix a few annoyances.
    Here are the changes:

    v2.28.3 (03. March 2021)
    Fixed: PhotonView.AmOwner was not updated.

    v2.28.2 (03. March 2021)
    Fixed: A potential issue with the execution order of the PhotonView component. It now sets it's own execution order to -16000 to get initialized before other scripts (especially on scene loading).
    Changed: Conditionals and logging output for Xbox builds. In the Editor, it's impossible to get a token, so PUN should not enforce this.
    Changed: PhotonView.ControllerActorNr will make sure the PhotonNetwork.LocalPlayer is not null when accessing the actorNumber through that.
    Changed: Instantiate will set PhotonView lastOnSerializeDataSent and lastOnSerializeDataReceived to null (which keeps instantiation for reused objects cleaner).
     
    Last edited: Mar 3, 2021
  16. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    We updated PUN 2 in the Asset Store. Now, development and upload happens in 2018.4.22!

    If you update a project that runs on Scripting Runtime Version ".Net 3.5", please set it to .Net .Net 4.x as we use .Net Standard 2.0 dlls by default now. Alternatively use the PhotonLibs\Photon3Unity3d.dll via the inspector settings.

    v2.29 (15. March 2021)
    Updated: Minimum supported Unity version to 2018.4.x. We develop PUN 2 in Unity 2018.4.22 from now on. Also the language compatibility level '.Net 4.x' or '.Net Standard 2.0' is now expected.
    Updated: Export settings for the dlls in Assets\PhotonLibs. All platforms will use .Net Standard 2.0, except the UWP export with .Net Runtime (which uses Metro with a placeholder being the lib in PhotonLibs\).
    Removed: Setting of protocol 1.6 when connecting directly to a Master Server. This was a workaround for older Photon Server SDKs.
    Note: If you host Photon yourself, you can set the LoadBalancingClient.SerializationProtocol to SerializationProtocol.GpBinaryV16, before you connect.
    Fixed: The PhotonView's "Find" button was not saving the observed components in scenes, which meant the script wasn't called at runtime.
    Added: IPunOwnershipCallbacks.OnOwnershipTransferFailed. This helps react when an Ownership Transfer request failed (due to earlier changes). This might mean you have to implement OnOwnershipTransferFailed in some scripts.
    Changed: PhotonView OwnerActorNr and ControllerActorNr to make use of the new Room.GetPlayer() option (to get the Master Client instance if the owner/controller is set to 0).
    Updated: Library to 4.1.5.2.
     
    Last edited: Mar 29, 2021
  17. MrBlueSky

    MrBlueSky

    Joined:
    Jan 7, 2013
    Posts:
    14
    Hello,

    I just switched a copy of one of my projects to Unity 2020.3.2f1 and updated to the latest version of PUN2, and now I have a NullReferenceException on NetworkingClient.AddCallbackTarget(target) in the PhotonNetworkPart.cs.

    NullReferenceException: Object reference not set to an instance of an object
    Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:109)
    Photon.Pun.MonoBehaviourPunCallbacks.OnEnable () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:111)

    I use Unity RuntimeInitializeOnLoadMethod with RuntimeInitializeLoadType.BeforeSceneLoad to instantiate my managers that are both derived from MonoBehaviourPunCallbacks.
    If I use RuntimeInitializeLoadType.AfterSceneLoad, it is working fine.
    I don't have the error with Unity 2020.1.17f1.
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    PUN 2 also uses RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad), so this is a race condition and you probably were lucky to not have the issue before.

    Registration for callbacks is only possible after PUN 2 was initialized.
    Can you add your managers to the initial scene and have them initialized with the rest of the code?
     
  19. MrBlueSky

    MrBlueSky

    Joined:
    Jan 7, 2013
    Posts:
    14
    Of course I can use AfterSceneLoad but is there not a way to solve this with execution order ?
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    I don't know if execution order also applies to this attribute. You'd have to figure out.
     
  21. somosky

    somosky

    Joined:
    Feb 15, 2014
    Posts:
    137
    @tobiass Hi so I'm using Opsive's Ultimate Character Controller and running into this issue.

    So I've used UCC and the Pun 2 addon before and have never had this issue.

    First of all the demo scene works fine. So there's certainly nothing wrong with the asset in general.

    However I've created several different characters to test this out with and they all give the same error message.

    "Changing a ViewID while it's in use is not possible (except setting it to 0(not being used)."

    I've created the characters in the normal way to set up characters. Then I have added them to the addon screen and set them up for pun. Then created them as prefabs and set them into the pun game object to be instantiated. However I get this error message every time. Even if I bring my character into the demo scene and add it into the pun game object it still doesn't work.

    It seems to be a issue of the characters photon view not changing when it is instatiated. For example in the prefab screen the photon view says "Set at Runtime" however if I drag the prefab into the scene it states a number (example :300). So when the player in created that 300 number does not change and that's where I am getting my error.

    In the editor console it's pointing to SpawnManagerBase cs 144 and SpawnManagerBase cs 95.

    I know that Nolan is working in the demo scene but could someone try converting another character to a pun character for a test because I'm wondering if something isn't working correctly with the editor window for creation.

    Also I'm on Unity 2020.3.1f1 LTS.
     
    Last edited: Apr 7, 2021
  22. jadeboye59

    jadeboye59

    Joined:
    Mar 27, 2021
    Posts:
    1
    Please how do i load my scenes as rooms using photon.
     
  23. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,580
    We just released PUN v2.30. This is a small-ish release with some fixes for ownership handling and some additional checks to prevent usage errors. If your workflow now stops where you didn't expect it, check the console output.

    v2.30 (13. April 2021)
    Changed: When the PhotonView.ControllerActorNumber should be set to 0, it now sets the backing field to the Master Client's actorNumber instead. This prevents misunderstandings when updates are sent with the Master Client's actual actorNumber
    Changed: Setting the PhotonView.ControllerActorNumber will now refresh the Controller in all cases. This makes sure that (e.g.) scene objects get a Controller value OnJoinedRoom (they might exist before a room is joined).
    Updated: EventSystemSpawner to log an error and pause the execution, if only the new input system is being used. The PUN demos are not compatible with it unless you set Active Input Handling to "Both".
    Note: Only the PUN demos are incompatible with the new input system. PUN itself is not affected. As the demos are in separate folders, you can easily delete all of them and use the new input system in your project.
    Updated: Realtime API to 4.1.5.4, preventing several error cases.
     
  25. xi_Michael

    xi_Michael

    Joined:
    Oct 21, 2020
    Posts:
    1
    Hello @tobiass

    I am trying to find a way to reconnect to MasterServer after disconnecting from Photon and then using Application.Unload. If I unload Unity, when I try to reconnect I will get hung up on ConnectingToNameServer. If I use Application.Quit instead of releasing memory with unload then I am able to reconnect and all is well.

    The problem is I cannot use App.Quit since in my case,Unity is a child of a native iOS app and it consequently quits the parent native app as well. Unload is what we need to use to have Unity put in the background after a game is over but it is causing issues with reconnecting back to MasterServer to then search for a lobby.

    I was wondering if I could get any insight on this? Perhaps some memory is being released on Unload that Photon is requiring?

    Thanks in advance.
     
    RMurphyXIMedia likes this.
  26. RMurphyXIMedia

    RMurphyXIMedia

    Joined:
    Oct 20, 2020
    Posts:
    2
unityunity