Search Unity

Third Party Photon Unity Networking

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

  1. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    The player's scripts attached:
     

    Attached Files:

  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Ok, so that is the same link I recommended. :) It is a very good series. Have you gone through the whole series or just that one lesson?

    The thing is, you are making a fundamental change here to the mechanism for all players to progress into the next scene. If your code was working with
    PhotonNetwork.automaticallySyncScene = false;
    , then all connected participants must have handled this transition and changed scenes themselves.

    If you now change to using
    PhotonNetwork.automaticallySyncScene = true;
    , the other clients must no longer do their own scene change (see my comment here).

    This is why I am asking if you have gone through the whole tutorial and not just one single lesson? :)
     
  3. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    I have gone through all the tutorial. I have a big (over 400 pages) document with all the Photon knowledge I was able to find in the Internet, so I know the theory. The problem is how to make a real game.

    I'm watching the Tank tutorial because I need to know how to handle a bullet in networking. Photon is a great stuff. We hope to use it for enterprise level, but first I need to learn basics and know how it works.
     
  4. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    If I could make a couple of observations :

    First, do remember to use code tags when posting code, although I see that is an inspector view, not code. :)

    Second, you are observing and continuously transmitting a lot of data there. You really want to keep network traffic to an absolute minimum.

    Good stuff. I just wanted to check that.

    ---

    So, to focus on your problem- have you had the linked scene transition working at any point? The reason I am asking is that, as mentioned before, the mechanism for transitioning to another scene is very different depending on whether
    automaticallySyncScene
    is true or false.
     
  5. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Just for testing now. I will try to make the traffic more minimal.
     
  6. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    It works, when
    PhotonNetwork.automaticallySyncScene = true;
    if false, my other clients cannot join the master somehow. With true, the problem happens with the three players.
    I can move the players, shoot etc, but the Master move two players LOL.
    I have the original code like in the tutorial, but this one change plus my own character. I also added:

    Code (CSharp):
    1. private void Update(){
    2.         if(PhotonNetwork.connectionStateDetailed.ToString() != "Joined"){
    3.             TextInfos.text = PhotonNetwork.connectionStateDetailed.ToString();
    4.         }else{
    5.             TextInfos.text = "Room: " + PhotonNetwork.room.name + " " + "Players: " + PhotonNetwork.room.playerCount + " " + "Master: " + PhotonNetwork.isMasterClient;
    6.         }
    7.     }
    To get a connection info.

    Ah, I changed the spawn function:
    Code (CSharp):
    1. [PunRPC]
    2.     private void RPC_CreatePlayer(){
    3.      
    4.         Debug.Log("Test");
    5.         //float randomValue = Random.Range(0f, 5f);
    6.         //Vector3 spawnPoint = new Vector3(3505.0f,52.2f,615.0f);
    7.         GameObject spa = GameObject.Find("SpawnPoints");
    8.         if(spa){
    9.             foreach (Transform child in spa.transform){
    10.                 spawns.Add(child);
    11.             }
    12.         }
    13.         int sp = Random.Range(0,spawns.Count);
    14.         Debug.Log(sp);
    15.         Vector3 spawnPoint = spawns[sp].position;
    16.         GameObject obj = PhotonNetwork.Instantiate(Path.Combine("Prefabs", player), spawnPoint, Quaternion.identity, 0);
    17.         CurrentPlayer = obj.GetComponent<PlayerMovementPN>();
    18.     }
    I needed more than one spawn point. It chooses a random spawn point from a list of spawn points. And spawn OK. Sometimes one player on the top of another, but for testing it is great.
     
    Last edited: May 31, 2018
  7. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    So you are up and running again? Good news. :)
     
  8. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    yes, but still three players.
     
  9. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Ok, so your
    RPC_CreatePlayer
    is presumably being called 3 times? I'm guessing once from the client and twice from the master maybe.

    Have you tried running as master and adding a breakpoint in the
    RPC_CreatePlayer
    to see if it is calling it twice?
     
  10. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    It was my first idea that it is called twice, so I used the Debug.Log().

    I'm trying again with
    PhotonNetwork.automaticallySyncScene = true;

    I build the instance of the game. Start it first, so we have the master client - I look around - one character. All works.
    Start the game in the editor - a regular client. Join the room with the master, two players added. The Debug.Log called ONLY ONE TIME. So the function is called only once.
    When I try to in another way, first Editor and then build The Debug.Log called ONLY ONE TIME. So again the function called only once, but three players.
    The difference is that Unity complains that two audio listeners in the scene
    Maybe I should use the GUI to show how many times the function is called in builds too.
     
  11. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Can you paste all the code paths that make calls to
    RPC_CreatePlayer
    .
     
  12. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93

    It is advisable not to transmit the id and viewid in the functions of the rpc
    1) Because of this, the network code becomes more complex. They are all already initialized(id and viewid).
    2) You pass more arguments to the function rpc(int array instead of int). You pass more bytes over the network. The more bytes and network messages are transferred, the faster the CPU is loaded.

    the syntax rule for PUN -
    In the signature of the function rpc, a parameter of type PhotonMessageInfo must be declared the last
    Functional PUN allows you to find everything you need -
    Code (CSharp):
    1.     [PunRPC]
    2.     public void ExampleRpc(int exampleVariable,PhotonMessageInfo info)
    3.     {
    4.         Debug.LogError(PhotonNetwork.player.ID); // ID of the one who got the function rpc
    5.         Debug.LogError(photonView.ownerId); // ID of the owner of the network object from which the function rpc is called.
    6.         Debug.LogError(info.sender.ID);// ID of the one who sent the function rpc to all
    7.         Debug.LogError(info.sender.IsLocal); // The one who sent this function rpc to everyone. When it receives this function, info.sender.IsLocal = true
    8.         Debug.LogError(photonView.viewID); // viewID of the owner of the network object from which the rpc function is called.
    9.         Debug.LogError(info.photonView.viewID); // viewID of the one who sent the rpc function to all
    10.     }
    For example, the first player(left)(id=1,viewID=1001) sends the rpc to everyone.



    Describe a more detailed description of the behavior of network objects.How do fighters interact with object X?
     
  13. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    The new code with a counter (this code works):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using UnityEngine;
    5. using UnityEngine.SceneManagement;
    6. using UnityEngine.UI;
    7.  
    8. public class PlayerNetwork : MonoBehaviour {
    9.  
    10.     public static PlayerNetwork Instance;
    11.     public string PlayerName { get; private set; }
    12.     private PhotonView PhotonView;
    13.     private int PlayersInGame = 0;
    14.     private ExitGames.Client.Photon.Hashtable m_playerCustomProperties = new ExitGames.Client.Photon.Hashtable();
    15.     private PlayerMovementPN CurrentPlayer;
    16.     private Coroutine m_pingCoroutine;
    17.     public string player;
    18.     public string sceneToLoad;
    19.     public static int counter;
    20.     private Text instanceText;
    21.  
    22.     public List<Transform> spawns = new List<Transform>();
    23.  
    24.     // Use this for initialization
    25.     private void Awake(){
    26.         Instance = this;
    27.         PhotonView = GetComponent<PhotonView>();
    28.  
    29.         PlayerName = "Player#" + Random.Range(1000, 9999);
    30.  
    31.         PhotonNetwork.sendRate = 60;
    32.         PhotonNetwork.sendRateOnSerialize = 30;
    33.      
    34.         SceneManager.sceneLoaded += OnSceneFinishedLoading;
    35.     }
    36.  
    37.     void Start(){
    38.         counter = 0;
    39.     }
    40.  
    41.     private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode){
    42.         if (scene.name == sceneToLoad){
    43.             if (PhotonNetwork.isMasterClient)
    44.                 MasterLoadedGame();
    45.             else
    46.                 NonMasterLoadedGame();
    47.         }
    48.     }
    49.  
    50.     private void MasterLoadedGame(){
    51.         PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient, PhotonNetwork.player);
    52.         PhotonView.RPC("RPC_LoadGameOthers", PhotonTargets.Others);
    53.     }
    54.  
    55.     private void NonMasterLoadedGame(){
    56.         PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient, PhotonNetwork.player);
    57.     }
    58.  
    59.     [PunRPC]
    60.     private void RPC_LoadedGameScene(PhotonPlayer photonPlayer){
    61.        PlayerManagement.Instance.AddPlayerStats(photonPlayer);
    62.      
    63.         PlayersInGame++;
    64.         if (PlayersInGame == PhotonNetwork.playerList.Length){
    65.             print("All players are in the game scene.");
    66.             PhotonView.RPC("RPC_CreatePlayer", PhotonTargets.All);
    67.          
    68.         }
    69.     }
    70.  
    71.     [PunRPC]
    72.     private void RPC_LoadGameOthers(){
    73.         PhotonNetwork.LoadLevel(1);
    74.     }
    75.  
    76.     [PunRPC]
    77.     private void RPC_CreatePlayer(){
    78.         instanceText = GameObject.Find("InstanceText").GetComponent<Text>();
    79.         counter++;
    80.         instanceText.text = counter.ToString();
    81.      
    82.         Debug.Log("Test");
    83.         //float randomValue = Random.Range(0f, 5f);
    84.         //Vector3 spawnPoint = new Vector3(3505.0f,52.2f,615.0f);
    85.         GameObject spa = GameObject.Find("SpawnPoints");
    86.         if(spa){
    87.             foreach (Transform child in spa.transform){
    88.                 spawns.Add(child);
    89.             }
    90.         }
    91.         int sp = Random.Range(0,spawns.Count);
    92.         Debug.Log(sp);
    93.         Vector3 spawnPoint = spawns[sp].position;
    94.         GameObject obj = PhotonNetwork.Instantiate(Path.Combine("Prefabs", player), spawnPoint, Quaternion.identity, 0);
    95.         CurrentPlayer = obj.GetComponent<PlayerMovementPN>();
    96.     }
    97.  
    98.     private IEnumerator C_SetPing(){
    99.         while (PhotonNetwork.connected){
    100.             m_playerCustomProperties["Ping"] = PhotonNetwork.GetPing();
    101.             PhotonNetwork.player.SetCustomProperties(m_playerCustomProperties);
    102.  
    103.             yield return new WaitForSeconds(5f);
    104.         }
    105.  
    106.         yield break;
    107.     }
    108.  
    109.  
    110.     //When connected to the master server (photon).
    111.     private void OnConnectedToMaster(){
    112.         if (m_pingCoroutine != null)
    113.             StopCoroutine(m_pingCoroutine);
    114.         m_pingCoroutine = StartCoroutine(C_SetPing());
    115.     }
    116.  
    117.     /* public void NewHealth(PhotonPlayer photonPlayer, int health){
    118.         PhotonView.RPC("RPC_NewHealth", photonPlayer, health);
    119.     }
    120.  
    121.     [PunRPC]
    122.     private void RPC_NewHealth(int health){
    123.         if (CurrentPlayer == null)
    124.             return;
    125.  
    126.         if (health <= 0)
    127.             PhotonNetwork.Destroy(CurrentPlayer.gameObject);
    128.         else
    129.             CurrentPlayer.Health = health;
    130.     } */
    131.  
    132. }
    133.  
    134.  
    135.  
     
    Last edited: May 31, 2018
  14. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Ok, and before I comment on it, which type of scene loading are you wanting to do automaticallySyncScene = true or false?
     
  15. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    automaticallySyncScene = true, of course.
    My additional code to show the counter on the UI blocks the second client joining the room with master. I don't know where to write the counter and GUI code to work on all clients.
    The code is:
    Code (CSharp):
    1. counter++;
    2. instanceText.text = counter.ToString();
     
  16. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    In that case, you don't need any of the scene handling code. Remove
    SceneManager.sceneLoaded += OnSceneFinishedLoading;
    . Make you sure only the master client calls LoadLevel.
     
  17. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    But why with
    automaticallySyncScene = false

    as was in the original code in the tutorial, doesn't work?

    The counter works now! I know where the additional code to place. I will replace the code again.
     
  18. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    I'm analyzing the situation:
    I start the first build - Master - counter: 1
    I start the second build - Client - counter: 1 and Master - counter: 2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    How it is possible?!!!!!!!!!!!
     

    Attached Files:

    Last edited: May 31, 2018
  19. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    All theese issues sound very basic and as others pointed you should go trough documentations and tutorials first. There is a demo folder inside Photon folder once you import the package. There was a simple yet very instructing marco polo tutorial. Make sure that for carácter insantiation you're using JUST , photon network instantiation and not the offline instantiate + online instantiation code. You'll have to write your code for online + ofline modes if you feature both modes. You also have to have the input scripts dissabled and enable only if for instance the root PhotonView has the .IsMine==true
     
  20. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Thank you, but I know that and all is done according to the tutorial. No other instantiation, only the one in the code presented here. I will try to remove
    SceneManager.sceneLoaded += OnSceneFinishedLoading;
     
  21. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    The code works with
    automaticallySyncScene = false
    but I need to do the following things:
    Start the Master, start the Client, make a room on the Master, join the room by the Client, the "Start Sync" button clicked by Master and both players go into the scene. BOTH! No three players, but only two! I wonder why the process looks in this way. I started the third instance (the second Client) and I cannot enter the game to join them. These rules are unclear for me. Should all the clients be in the room and then Master starts the game with all the Clients and other Clients cannot join them. It is really confusing. I need to read more to understand that.
     
  22. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    There are many considerations of lobbies, rooms, one master and multiple clients, owning objects, order of events, dropped connections, disconnections etc.

    It really is a lot of things to keep track of. That is why I would recommend really going through the whole tutorial that both myself and you, linked above. It takes you step, by step, through all these considerations. Of course, it will take time to sit through them all and really let the details sink in. But worth it in the end. Trying to solve this stuff by trial and error is going to be a thankless task. :)
     
  23. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Thank you for your precious help. I have gone through the tutorial, and I see I should do that again. Now, I need to finish the tank tutorial in French.
     
    Doug_B likes this.
  24. Rebe_FoofaStudios

    Rebe_FoofaStudios

    Joined:
    Mar 4, 2016
    Posts:
    1
    Hi!
    Is it possible to sync only room custom properties, but keep every other message disabled?
    Setting PhotonNetwork.isMessageQueueRunning to false disable everything, but i'd like to keep properties synced

    Thanks
     
  25. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I have an object which I reference throughout my game. I just attached a photonView to it, and now, once joined network, is destroyed.
    Why?
     
    Last edited: May 31, 2018
  26. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi I am running into an issue with this....
    Code (csharp):
    1.  
    2.     [PunRPC]
    3.     public override void OnPhotonInstantiate(PhotonMessageInfo info)
    4.     {
    5.         // e.g. store this gameobject as this player's charater in PhotonPlayer.TagObject
    6.         info.sender.TagObject = this.gameObject;
    7.         int viewID = info.photonView.viewID;
    8. }
    9.  

    My idea is, OnPhotonInstantiate(), will allow me to gather info, via info, about the object that created this. However, My system crashes at the last line, int viewID = info.photonView.viewID;. I get a null reference exception. So I presume the photonView does not exist on the sender, but to the best of my abilities, it does.


    Any ideas?
     
  27. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    In spawning a player, local to the client, should this player be spawned via this client?
     
  28. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    You mixed it all together. There is a transmission of network data - PhotonNetwork.Instantiate and there is another type of transmission of network data - the function rpc. Do not mix them up - these are different concepts.

    PhotonMessageInfo info in OnPhotonInstantiate does not have info.photonView. The spawner of the network object (PhotonNetwork.Instantiate) is not a PhotonView, it is PhotonPlayer - it does not have a viewID(info.photonView.viewID), it only has ID(info.sender.ID).
     
  29. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    How to get a gameObject of all players in the room? To get for example a component? It's seems simple but I cannot find the way to do that. A PhotonNetwork.playerList provides us with PhotonPlayers and now how to get their gameObjects?
     
  30. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    hi there,
    Running a stand-alone build and running the editor buid, the Unity Time.time runs much faster (almost double) on the standalone.

    Is this just because the editor requires much more CPU power? Or do I need to not use (in my case) Update()? And if I can’t rely on Update for consistent frame rates, what can I use?
     
    Last edited: Jun 3, 2018
  31. chunnomi

    chunnomi

    Joined:
    Dec 13, 2014
    Posts:
    3
    Hi, there.

    Now I'm trying to develop a fighting game on PC and mobile phone
    and make 2 players synchronize completely by sending just user inputs frequently.
    So is it possible and practical to send simple and small data very frequently (like about 30 times per second)
    between 2 players on PUN?

    For an experiment, I've used PhotonView script/OnPhotonSerializeView method and
    change the member variable of the observed component every 2 frames
    so that the data will be sent at the frequency. (Synchronizaton = "Unreliable On Change" at Photon View Script)
    But actually the data were sent less frequently (every 3 or 4 frames) than I had expected.

    Is there any way to control freqcency at which data are actually sent and make sure that data are sent immediately with no buffering?
    Or am I missing something?
     
  32. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Bump!
     
  33. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    create a static list of player objects

    In the player's objects - in the start or awake function, add the element to the list. I do not understand what your difficulty is.
    What are your data values FPS in tests? stand-alone build and editor buid = 60 fps ?
    always use only the reliable delta compressed (have ACK package)
    unreable and unreable on change - unreliable transmission of packets of movement . The package(unreable message) may not reach the recipient(Player) . This package does not have an ACK package which is responsible for 100% sending to the recipient.
    of course unreable messages are not lost often. BUT. If it happens. This is a very significant big loss. The loss of one movement packet is not the loss of one point of movement, it is the loss of a segment of the Lerp (a set of points of movement)
     
    Last edited: Jun 5, 2018
  34. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697

    Hi, in relation to different frame rates in stand alone vs editor.....
    At the moment I am just monitoring Time.time..... in which case the editor is running at about 2/3rds of the stand alone. So, I am trying to think about how to insure a much more similar rate.... or if the issue is the fact one is a stand lone build, which will generally run the same across the network, vs on running in the editor, which may have more to process and thus slower.

    I understand Photon.TIme is the same across all clients. Is there a Photon.Update() that I can replace Unity.Update() with?
     
  35. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    The following code showing the problem:

    Code (CSharp):
    1.  foreach(PhotonPlayer player in PhotonNetwork.playerList){
    2. MK_UIController mk_UIController = player.[SOMETHING].GetComponent<MK_UIController>();
    3. mk_UIController.AddMessage("Player " + other.NickName + " Left Game.");
    4. }
    How to iterate through the list of players to get their components so that I can call a function on them? What should be instead of the SOMETHING placeholder so that the code works? Hope it is clear what I meant.
     
    Last edited: Jun 5, 2018
  36. chunnomi

    chunnomi

    Joined:
    Dec 13, 2014
    Posts:
    3
    Hi, Kurtav.

    I'm sorry what I post might be not so clear or confusing.

    What I really meant is that I wanted to use OnPhotonSerializeView method to send simple data at the high frequency I need,
    but even if I changed the value of the observed component every frame,
    OnPhotonSerializeView was called far less frequently.

    Actually I just found the solution today.
    The frequency at which data are sent and OnPhotonSerializeView is called is defined by
    PhotonNetwork.sendRate(20 times per sec by default) and
    PhotonNetwork.sendRateOnSerialize(10 times per sec by default).

    I made sure that by changing these values from script, I can send data at the frequency I want.

    Thanks anyway.
     
    Last edited: Jun 7, 2018
  37. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    I do not understand you. Record a video of the computer desktop (bandicam or shadowplay,etc)
    Show me a specific problem. With all indicators
    and please add this script to the canvas before recording.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. namespace UnityStandardAssets.Utility
    4. {
    5.     [RequireComponent(typeof (Text))]
    6.     public class FPSCounter : MonoBehaviour
    7.     {
    8.         const float fpsMeasurePeriod = 0.5f;
    9.         private int m_FpsAccumulator = 0;
    10.         private float m_FpsNextPeriod = 0;
    11.         private int m_CurrentFps;
    12.         const string display = "{0} FPS";
    13.         private Text m_Text;
    14.  
    15.         private void Start()
    16.         {
    17.             m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
    18.             m_Text = GetComponent<Text>();
    19.         }
    20.  
    21.         private void Update()
    22.         {
    23.             // measure average frames per second
    24.             m_FpsAccumulator++;
    25.             if (Time.realtimeSinceStartup > m_FpsNextPeriod)
    26.             {
    27.                 m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod);
    28.                 m_FpsAccumulator = 0;
    29.                 m_FpsNextPeriod += fpsMeasurePeriod;
    30.                 m_Text.text = string.Format(display, m_CurrentFps);
    31.             }
    32.         }
    33.     }
    34. }
    35.  
    Do you want to find the desired object of the player through the class of the PhotonPlayer?
    for example like this? -
    Code (CSharp):
    1. List<GameObject> players;
    2. foreach(PhotonPlayer player in PhotonNetwork.playerList)
    3. players[player.ID];
     
  38. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697


    So, my issue essentially is maintaining a consistent Frame Rate across the network.

    In my code, I use Update(). However since frame rate (thus speed at which Update() is updated) in different builds, can fluctuate wildly. This is not ideal.
     
  39. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Hi.

    I'm getting a very rare exception.

    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in <filename unknown>:0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in <filename unknown>:0
    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.<CallInBackground>b__0 () [0x00000] in <filename unknown>:0
    UnityEngine.Debug:Internal_LogException(Exception, Object)
    UnityEngine.Debug:LogException(Exception)
    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    UnityEngine.EventSystems.StandaloneInputModule:processMousePress(MouseButtonEventData)
    UnityEngine.EventSystems.StandaloneInputModule:processMouseEvent(Int32)
    UnityEngine.EventSystems.StandaloneInputModule:processMouseEvent()
    UnityEngine.EventSystems.StandaloneInputModule:process()
    UnityEngine.EventSystems.EventSystem:Update()

    (Filename: Line: -1)


    Then I get a zillions of this kind of exceptions:
    NullReferenceException: Object reference not set to an instance of an object
    at PhotonNetwork..cctor () [0x00000] in <filename unknown>:0
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PhotonNetwork
    at PhotonHandler.FallbackSendAckThread () [0x00000] in <filename unknown>:0

    at ExitGames.Client.Photon.SupportClass+<>c__DisplayClass1.<CallInBackground>b__0 () [0x00000] in <filename unknown>:0

    (Filename: Line: -1)

    I find this only in the log of the game, In editor all works perfectly. Further in the UWP build all works fine. Any clues?

    I've even restored the older photon from a backup but that seems not to be the case.

    I've moved teh assets folder into a blank project and issue persists.

    This error is trown in the menu, this is a mature project and I've changed nothing in teh menu.


    EDIT:
    same issue here:
    https://forum.photonengine.com/discussion/6658/photon-errors-only-on-standalone-build

    As I recently updated to 1.88 this could be it but I believe I restored old photon and kept getting the error. Further, I'm getting super weird issues in runtime like menu camera can not be instantiated but It does instantiate in the end so believe is due to photon messing around

    EDIT2 as I was suspecting I'm already on the old 1.66 verison. Just gonna overide all with version from the working backup just in case the dll are from the 1.88

    EDIT3: restored photon form the working verison. issues persist. :\
     
    Last edited: Jun 7, 2018
  40. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Yes, I had no idea how to do that. So I need to create my own list for game objects of players during instantiating them. No list of them created automatically by Photon?
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Tomza:
    PUN has a list of PhotonViews but it's not sharing that with you. Problem is (as usual) that it should not be modified externally and to avoid issues, we're not providing such a list. It's not useful all that often, we assumed, if each object does what it's expected to do.
    What is your usecase?

    @TooManySugar:
    The problems you describe are unknown to us. Can you mail us to developer@photonengine.com and let us know your Unity version, PUN version and a way to reproduce this? If you import our package into a new, empty project, can you reproduce the issue with specific build settings?
     
  42. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Hi Tobias,

    i just wanted to get all gameObject players to call a function in the script that each player has. Just like in a regular Unity scripting. I have a list of objects, iterate through them getting their script and call a given function. In my case, I wanted to send some info to them. And I wished to get those objects using PhotonPlayers. Like in the code I wrote above. Wouldn't it useful?
     
  43. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    sure, I need to do bit more testing first.

    Now I did create an empty project, and droped whole assets folder.

    getting this err.
    This ne err is solved by deleting demos folder, now I'm going to make a build and test if issues persist.

    upload_2018-6-7_17-18-19.png

    upload_2018-6-7_17-18-26.png

    The folder exists. The only thing I modified so far is that I use a custom Json.net dll


    DirectoryNotFoundException: Directory 'G:/TWP/empty/Assets/Photon Unity Networking' not found.
    System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:514)
    System.IO.Directory.GetDirectories (System.String path, System.String searchPattern) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:275)
    System.IO.Directory.GetDirectoriesRecurse (System.String path, System.String searchPattern, System.Collections.ArrayList all) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:290)
    System.IO.Directory.GetDirectories (System.String path, System.String searchPattern, SearchOption searchOption) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:284)
    PunStartup.SetPunDemoBuildSettings () (at Assets/Assets/Photon Unity Networking/Demos/DemoHub/Editor/PunStartup.cs:86)
    PunStartup.OnUpdate () (at Assets/Assets/Photon Unity Networking/Demos/DemoHub/Editor/PunStartup.cs:52)
    UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/artifacts/EditorGenerated/EditorApplication.cs:235)
     
    Last edited: Jun 7, 2018
  44. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    I can't help thinking that using RaiseEvent might be the best way to approach this.
     
  45. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Maybe. I learn Photon. I just thought that it could use a Unity way of communication among objects. Just iterating through the playerList, get their gameObjects, then their components (scripts), and call a given function.
     
  46. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @TooManySugar: The path in the inspector has Assets/Assets/ while the error message has just one? If you drop the Demos, the editor scripts to setup the demos for a build won't work (of course). Obviously, we should make our editor script more error resistant and pretty print a message that the demos are not found...

    @Tomza: If you want to let scripts know about events within the network room, you should use IPunCallbacks or implement a PunBehaviour instead of a MonoBehaviour. The PunBehaviour implements IPunCallbacks and you leverage PUN's internal way to let scripts know when players join / leave. You won't have to invent that wheel.

    If you have a usecase not covered by this logic and the implemented callbacks, then you will (currently) have to build a list of objects that are interested in whatever event you want fired / handled. If a script implements void OnPhotonInstantiate(PhotonMessageInfo info), this gets called when the object gets network-instantiated. It may register itself for such a list of events, etc. Alternatively, of course, all scripts can add themselves to a custom list in Awake() and remove themselves in OnDisable() and or OnDestroy() or something similar.

    In doubt, modify the NetworkingPeer and get a copy of the photonViewList, when you need it. This contains all PhotonViews but we don't usually hand it out, to prevent changes and such. Also, copying it on access is costly (and you should minimize that by caching).

    Let us know which use case you got, that's not covered by IPunCallbacks and which is not game-specific.
     
  47. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    93
    Code (CSharp):
    1. public class NetworkPlayer : Photon.MonoBehaviour
    2. {
    3.     static Dictionary<int, GameObject> players = new Dictionary<int, GameObject>();
    4.    
    5.     void Awake()
    6.     {
    7.         Debug.LogError("Set Dictionary ownerId = " + photonView.ownerId);
    8.         players.Add(photonView.ownerId, gameObject);
    9.  
    10.         Invoke("GetPlayersGameObject", 2);
    11.     }
    12.    
    13.     void GetPlayersGameObject()
    14.     {
    15.         foreach (PhotonPlayer player in PhotonNetwork.playerList)
    16.         {
    17.             Debug.LogError("Player.ID = " + player.ID );
    18.             Debug.LogError("Get Dictionary player.ID = " + players[player.ID]);
    19.         }
    20.     }
    21. }
     
    tobiass and Tomza like this.
  48. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864

    Ok may be I just had a folder killed or something, still the other issues did persist. SEems like the whole project collapsed but you know what. This was in 4.7. I was stuck in there forever. May be this is an oportunity to start clean, and port the whole thing to 2018. I'm already porting the menu, cherry picking each asset, checking each script looking for the need of refactoring etc. This will also help me to stay up to date with photon and other assets.
     
    Last edited: Jun 8, 2018
    tobiass likes this.
  49. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    @tobiass I am trying to better understand the OnPhotonSerializeView(). Google shows no direct link to a reference page, so I am wondering a few things, as my tests to better understand how to use it, are proving frustrating.I cant seem to get the calls I want on a player who is non local.

    so...


    1) OnPhotonSerializeView() this is called on any object with a PhotonView script, correct?
    2) It is called each frame over the network? So not unity time, but PhotonNetwork.time?
    3) My tests to non local players, are not retuning any of my data for console read. So OnPhotonSerializeView() if photonView.isMine, I get the data I expect. If !photonView.isMine, I do not get any data..... So I am puzzled as to why this might be.

    Code (csharp):
    1.  
    2.  
    3.     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    4.  
    5.  
    6.         double ptime = PhotonNetwork.time;
    7.         float ltime = Time.time;
    8.  
    9.  
    10.  
    11. //playerUnit_this.isLocal = photonView.isMine
    12.         if(playerUnit_this.isLocal){
    13.             if(playerUnit_this.PlayerInt == 1){
    14.  
    15.                 Loading_Mng.ins.tmp_debugger3.text = " P1 is Local. " + PhotonNetwork.time.ToString();
    16.                 if(stream.isWriting){
    17.                     Loading_Mng.ins.tmp_debugger3.text = " P1 is Writing local. " + PhotonNetwork.time.ToString();
    18.                 }
    19.  
    20.             }
    21.             if(playerUnit_this.PlayerInt == 2){
    22.  
    23.                 Loading_Mng.ins.tmp_debugger6.text = " P2 is Local. " + PhotonNetwork.time.ToString();
    24.                 if (stream.isWriting)
    25.                 {
    26.                     Loading_Mng.ins.tmp_debugger6.text = " P2 is Writing local. " + PhotonNetwork.time.ToString();
    27.                 }
    28.             }
    29.  
    30.         }
    31.         if (!playerUnit_this.isLocal){
    32.  
    33.             print(" ==========  this player non local ========== ");
    34.  
    35.             if (playerUnit_this.PlayerInt == 1)
    36.             {
    37.                 print(" ==========  this player 1 non local ========== ");
    38.                 Loading_Mng.ins.tmp_debugger2.text = " P1 is !!!Local. " + PhotonNetwork.time.ToString();
    39.                 if (stream.isWriting)
    40.                 {
    41.                     print(" ==========  this player 1 non local is writing  ========== ");
    42.                     Loading_Mng.ins.tmp_debugger2.text = " P1 is Writing !local. " + PhotonNetwork.time.ToString();
    43.                 }
    44.                 if(stream.isReading){
    45.                     print(" ==========  this player 1 non local is reading  ========== ");
    46.                 }
    47.  
    48.             }
    49.             if (playerUnit_this.PlayerInt == 2)
    50.             {
    51.                 print(" ==========  this player 2 non local ========== ");
    52.                 Loading_Mng.ins.tmp_debugger5.text = " P2 is !!!Local. " + PhotonNetwork.time.ToString();
    53.                 if (stream.isWriting)
    54.                 {
    55.                     print(" ==========  this player 2 non local is writing  ========== ");
    56.                     Loading_Mng.ins.tmp_debugger5.text = " P2 is Writing !local. " + PhotonNetwork.time.ToString();
    57.                 }
    58.                 if (stream.isReading)
    59.                 {
    60.                     print(" ==========  this player 2 non local is reading  ========== ");
    61.                 }
    62.             }
    63.  
    64.         }
    65.  
    66.  
    67.  
    68.     }
    69.  
     
  50. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Clear! Thank you.