Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all 8947 articles
Browse latest View live

Reducing Network Traffic During Load By reducing use of room properties

$
0
0
Hello. I am working on reducing traffic during the load of our game. I notice the following code when a player disconnects: (only the master client executes this) bool isPlayer = (string)otherPlayer.CustomProperties[Strings.PLAYER_TYPE] == "Player" ? true : false; int playerCount = (int)PhotonNetwork.room.CustomProperties[Strings.PLAYER_COUNT]; int newPlayerCount = isPlayer ? playerCount - 1 : playerCount; int newSpecCount = !isPlayer ? spectatorCount - 1 : spectatorCount; ExitGames.Client.Photon.Hashtable roomProperties = new ExitGames.Client.Photon.Hashtable(); roomProperties.Add(Strings.PLAYER_COUNT, newPlayerCount); roomProperties.Add(Strings.SPECTATOR_COUNT, newSpecCount); PhotonNetwork.room.SetCustomProperties(roomProperties); These room properties are set in the game room before we load into our game scene. I don't see these properties used anywhere after we start our game. I just want to double check that it is ok to remove this code.

Display every player's name?

$
0
0
First, the player inputs his name into an input field. Then, the user presses a button and it loads the level. The player's movements are perfectly synchronized and everything, but their names don't show up properly. I've got a canvas attached to both players. It will show your name, but it won't show all the other user's names. How can I make it so that when a user joins the game, it will display everybody else's name? I'm a total noob :(

Photon SetCustomProperties not working for previously connected players

$
0
0
Hi I have some problem while using SetCustomProperties The code is like below: Hashtable playerCountryCode = new Hashtable() { { "CountryCode", "HK" } }; PhotonNetwork.player.SetCustomProperties(playerCountryCode); PhotonNetwork.JoinRoom(roomName); 3 players connected. Player1 (First Joined): shows all player's country code properly. Player2 (Joined secondly): shows Player2 and Player3's country code. Player3 (Last joined): shows only Player3's country code. I would like to solve this problem. Please help me to get all player's name correctly for all players. Look forward to hearing from you Here is the attachment https://pasteboard.co/HZzrtgA.png

Scene objects not deleted on other clients devices

$
0
0
When I try to delete scene objects created by master client , they are deleted on master client's device, however, some of them are still seen on other clients devices. This is my codes. if (PhotonNetwork.isMasterClient) { PhotonNetwork.Destroy(go66); <= this is deleted on master, not deleted on other clients. PhotonNetwork.Destroy(go6); <= this is deleted on master and other clients. } One thing,,, go66 used to be a child of go6 when it is created. Later go66 is released before getting destroyed. Can anyone help me on this? Thanks for any advice.

PUN 1.93 UWP build errors

$
0
0
Hello! We cannot build our game for UWP .NET4.6 with .NET Core due to multiple errors: Placeholder path on Assets/Plugins/Photon3Unity3d.dll is wrong: "Assets/Photon/PhotonLibs/Photon3Unity3D.dll". Changed it to "Assets/Plugins/Photon3Unity3D.dll". Then following errors appear: Assets\Photon Unity Networking\Plugins\PhotonNetwork\NetworkingPeer.cs(836,55): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) Assets\Photon Unity Networking\Plugins\PhotonNetwork\PingCloudRegions.cs(198,56): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) Assets\Photon Unity Networking\Plugins\PhotonNetwork\PingCloudRegions.cs(200,24): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) I've tried to compare code to PUN 2 but cannot fix it fast. Any workarounds?

US Region is down?

$
0
0
Was wondering why everything suddenly stopped working on my app, it seems like the us region is down since a few hours but not shown in photonengine status, im always stuck at connectingtomaster peer state. Changed to eu its working fine tought. Any idea if its the server that is down or me that got some other problem? Or maybe major internet outage?

photonView.RequestOwnership(); it does not work

$
0
0
I'm creating a multiplayer game and I would like to insert the grab system, I know I have to put photonView.RequestOwnership (); but I do it, it does not give me error, only when I take the object does not make me take, instead if I do not put photonView.RequestOwnership(); it works great, how do I solve it? on photonview I already put on "TakeOver" here are the codes of the files GrabObjects.cs photonView.RequestOwnership(); I put it inside the function, so it's okay? do you do it well? using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; [RequireComponent(typeof (PhotonView))] public class GrabObjects : Photon.MonoBehaviour { public float grabPower = 10.0f; public float throwPower = 25.0f; public float RayDistance = 3.0f; public LayerMask layerMask; private bool grab, drop = false; public Transform pos; public float adjust; Rigidbody obj; void Update() { if (Input.GetKeyDown(KeyCode.Mouse1)) { RaycastHit hit; if(Physics.Raycast(transform.position, transform.forward, out hit, RayDistance, layerMask.value)) { Pickable pickable = hit.collider.GetComponent(); if(pickable) { photonView.RequestOwnership(); grab = true; obj = hit.rigidbody; obj.isKinematic = true; obj.GetComponent().enabled = false; obj.transform.parent = pos; } } } if (Input.GetKeyUp(KeyCode.Mouse1)) { if(grab) { StartCoroutine(PrepareToDrop(3f)); } } if (Input.GetKeyDown(KeyCode.Mouse0)) { if(grab) { StartCoroutine(PrepareToDrop(throwPower)); } } if(grab) { obj.transform.position = Vector3.Lerp(obj.transform.position, pos.position + (pos.transform.forward * adjust) - (pos.transform.up * 0.4f), Time.deltaTime * grabPower); obj.transform.rotation = Quaternion.Lerp(obj.transform.rotation, pos.rotation, Time.deltaTime * 5f); } } IEnumerator PrepareToDrop(float power) { RaycastHit hits; while(!drop) { if(Physics.Raycast(transform.position, transform.forward, out hits, 1.5f, layerMask.value)) drop = false; else drop = true; yield return null; } obj.transform.parent = null; obj.isKinematic = false; obj.GetComponent().enabled = true; obj.velocity = transform.forward * power; drop = grab = false; } } Here is the other, this is empty is placed in the object reference point to make the script understand to take that object using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof (PhotonView))] public class Pickable : Photon.MonoBehaviour { }

Weird error when attempting to Add component "An item with the same key ... Photon View"

$
0
0
So as the title says, since updating to V2, I've been getting this error "ArgumentException: An item with the same key has already been added. Key: Component/Photon Networking/Photon View" whenever I press the "Add Component" button. I realized that for some reason, my editor has multiple copies of "Photon view" and I don't know why. See image https://imgur.com/a/l44Xozx . I've been scouring my folders to see if there were duplicates somewhere, but I found nothing. Any advice?

PUN doesn't find in-scene prefabs when loading the scene second time around

$
0
0
Sorry, the title is probably a bit confusing. I'm trying to do the following: I have a "Start Scene" in Unity, which is where the player starts and is off-line. when ready, they click a button to connect to photon and have it load the "Main Scene". Once the main scene is loaded, the player is instantiated by photon at the position and rotation of a prefab (ie, a spawn point). Once in the Main Scene, the player can click a button to disconnect from photon and return to the Start Scene. The problem is, this works perfectly the first time around, but once the player goes back to the Start Scene and then tries to repeat, once the Main Scene is loaded for the second time, I get this error message: MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. The spawnpoint is just a prefab that I've placed into the scene. There is no photon view or anything on it. I'm only using it to read it's position, and I know it's there the second time because I can see it in the editor scene view, but photon thinks it isn't. I know I'm probably just using a wrong command or something, but I can't figure out what it is, and I have no idea why photon thinks it's been destroyed because it didn't instantiate it in the first place. Here is the only script in the Start Scene(heavily condensed for brevity):

public class StartSceneScript : Photon.PunBehaviour
{
  public bool offlineMode = false;
  public byte MaxPlayersPerRoom = 6;
	
  void Awake()
  {
    PhotonNetwork.logLevel = Loglevel;
    PhotonNetwork.autoJoinLobby = false;
    PhotonNetwork.automaticallySyncScene = false;
  }

  public void LoadLevel()
  {
    ConnectToPhoton();
  }
	
  void ConnectToPhoton()
  {
    if (!PhotonNetwork.connected)
    {
      PhotonNetwork.ConnectUsingSettings("1");
    }
  }

  public override void OnConnectedToMaster()
  {
    PhotonNetwork.JoinRandomRoom();
  }
	
  public virtual void OnPhotonRandomJoinFailed()
  {
     PhotonNetwork.CreateRoom(null, new RoomOptions() {MaxPlayers = MaxPlayersPerRoom}, null);
   }
  
  public override void OnJoinedRoom()
  {
     PhotonNetwork.LoadLevel("MainScene");
  }
}
And here is the only script used in the Main Scene:

public class MainSceneScript : Photon.MonoBehaviour
{
  public GameObject playerPrefab;
  public GameObject spawnSpot;
	
  void OnEnable()
  {
    SceneManager.sceneLoaded += OnSceneLoaded;
  }
	
  void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  {
    if(PhotonNetwork.connected)
    {
	SpawnPlayer();
    }
  }
	
  void SpawnPlayer()
  {
    GameObject player	= PhotonNetwork.Instantiate(playerPrefab.name, spawnSpot.transform.position, 
    spawnSpot.transform.rotation, 0);
  }
	
  public void LoadStartScene()
  {
    PhotonNetwork.Disconnect();
    SceneManager.LoadScene("StartScene", LoadSceneMode.Single);
  }
}
Note: I'm not even concerned about other players joining yet or anything else. I'm just trying to track down why this error is occuring. The only thing I can think of is that maybe "PhotonNetwork.Disconnect();" isn't the right thing to do, but I need the Start Scene to be off line again once the player goes back into it. I've tried everything I can think of. Any thoughts as to why this is happening or what the proper way to do this would be?

2 Payer random matchmaking

$
0
0
Hello everyone, I am developing a game using Photonnetwork. I want to do this, 2 players enter the room when the game begins. Yes the game starts but the player who created the room cannot spawn.Other player can spawn. Only one player participates in the game. I'm spawning the user in the "updateOtherPlayerStatus()" method, where am I making mistakes? Thanks already for your help. My code;
 public void Connect()
    {
        car[CarSelected].carObj.GetComponent().enabled = true;
        PhotonNetwork.automaticallySyncScene = true;

        PhotonNetwork.PhotonServerSettings.HostType = ServerSettings.HostingOption.BestRegion;
        PhotonNetwork.ConnectToBestCloudServer(appVersion);
    }

    public override void OnFailedToConnectToPhoton(DisconnectCause cause)
    {
        if (connectionFailedEvent != null)
            connectionFailedEvent();
    }

    private IEnumerator requestJoinRandomRoom()
    {
        while (!PhotonNetwork.connectedAndReady)
        {
            yield return new WaitForEndOfFrame();
        };
        PhotonNetwork.JoinRandomRoom();
    }

    public void StartMatching()
    {
        StartCoroutine(requestJoinRandomRoom());
    }

    private void updateOtherPlayerStatus()
    {
        if (PhotonNetwork.room.PlayerCount == 2)
        {
            //messageLabel.text = @"Rakip Bulundu";
            //statusLabel.text = @"rakip: " + PhotonNetwork.otherPlayers[0].NickName;
            //cancelButton.interactable = false;
            //SpawnPlayer();
            PhotonNetwork.LoadLevel(1);

            if (!PhotonNetwork.isMasterClient)
                return;

            this.photonView.RPC("AddPlayer",PhotonTargets.All);
        }
    }
    /// 
    /// Called when something causes the connection to fail (after it was established).
    /// See the official Photon docs for more details.
    /// 
    public override void OnConnectionFail(DisconnectCause cause)
    {
        if (connectionFailedEvent != null)
            connectionFailedEvent();
    }

    public override void OnConnectedToMaster()
    {
        //set my own name and try joining a game
        PhotonNetwork.playerName = "Player"+ UnityEngine.Random.Range(1,9999);
        PhotonNetwork.JoinLobby();
    }

    public override void OnPhotonRandomJoinFailed(object[] codeAndMsg)
    {
        Debug.Log("Photon did not find any matches on the Master Client we are connected to. Creating our own room... (ignore the warning above).");

        PhotonNetwork.CreateRoom(null, new RoomOptions() { MaxPlayers = 2}, null);
    }

    public override void OnPhotonCreateRoomFailed(object[] codeAndMsg)
    {
        if (connectionFailedEvent != null)
            connectionFailedEvent();
    }

    public override void OnCreatedRoom()
    {
        Debug.Log("OnCreatedRoom");

        Hashtable roomProps = new Hashtable();
        roomProps.Add(RoomExtensions.size, new int[RoomExtensions.initialArrayLength]);
        roomProps.Add(RoomExtensions.score, new int[RoomExtensions.initialArrayLength]);
        PhotonNetwork.room.SetCustomProperties(roomProps);

    }

    public override void OnJoinedLobby()
    {
        Debug.Log("OnJoinedLobby");
        //statusLabel.text = @"Sen: " + PhotonNetwork.playerName;
        StartMatching();
    }

    public override void OnJoinedRoom()
    {
        PhotonPlayer player = GetComponent().owner;
        Debug.Log("Joined player(id: { player.ID }) in this room.");
        updateOtherPlayerStatus();
    }

    //IEnumerator WaitForSceneChange()
    //{
    //    while (SceneManager.GetActiveScene().buildIndex != onlineSceneIndex)
    //    {
    //        yield return null;
    //    }

    //    //we connected ourselves
    //    OnPhotonPlayerConnected(PhotonNetwork.player);
    //}
    public override void OnPhotonPlayerConnected(PhotonPlayer player)
    {
        updateOtherPlayerStatus();
    }


    //received from the master client, for this player, after successfully joining a game
    [PunRPC]
    void AddPlayer()
    {
        RCC_CarControllerV3 testArac;

        GameObject[] point = GameObject.FindGameObjectsWithTag("spawnpoint");
        int spawPointindex = UnityEngine.Random.Range(0, point.Length);

        testArac = PhotonNetwork.Instantiate(car[CarSelected].name, point[spawPointindex].transform.position, point[spawPointindex].transform.rotation, 0).GetComponent();

        RCC.RegisterPlayerVehicle(testArac);
        RCC.SetControl(testArac, true);

        if (RCC_SceneManager.Instance.activePlayerCamera)
            RCC_SceneManager.Instance.activePlayerCamera.SetTarget(testArac.gameObject);

        Gunes.instance.playerNameText = PhotonNetwork.playerName;
    }
    public override void OnPhotonPlayerDisconnected(PhotonPlayer player)
    {
        //only let the master client handle this connection
        if (!PhotonNetwork.isMasterClient)
            return;

        Gunes.instance.target = null;
    }

    public override void OnDisconnectedFromPhoton()
    {
        if (SceneManager.GetActiveScene().buildIndex != offlineSceneIndex)
            SceneManager.LoadScene(offlineSceneIndex);
    }

}

Oculus Avatars setup

$
0
0
Hey, I followed this tutorial to get Oculus Avatars to worK: https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/oculusavatarsdk I don't see my local avatar in game i.e. no hands or any indication it's loaded, on the other end on a remote client I can see my avatar but it doesn't show my personalised avatar and it doesn't follow my position if I move around locally (I use VRTK). Do I have to sync the positions separately and does the localavatar automatically attach to my scene OVRCameraRig even if I'm using VRTK which handles multiple setups? Thanks

4 - Game Manager & Levels

$
0
0
I am having issues with the code snippets, especially finding classes and variable for GameManager scripit. I have notice some typos that are causing the failed compiles such as isMasterClient, which is actually IsMasterClient, and following statements: if (!PhotonNetwork.isMasterClient) public override void OnPhotonPlayerDisconnected(PhotonPlayer other) public override void OnPhotonPlayerConnected(PhotonPlayer other) Any Help would be highly appreciated. Thanks

PhotonNetwork.OnEventCall doesn't exist

$
0
0
Hello, everything is in the title. Maybe API has changed ? Could you update docs if yes ? How can you subscribe a function to event raising since OnEventCall doesn't exist ? Thanks

Issues When Adding PhotonViews to GameObjects at Runtime

$
0
0
Hello! I am working on a game where I need to be able to add and remove PhotonViews to objects at runtime relatively frequently. I have a system where I add a PhotonView on the client side, then send the name of the GameObject, and the ViewID that I allocated to the PhotonView through a custom PhotonView (lets just call it SharedInfo) script that I have created. SharedInfo then sends the data over the network to itself (serializes it? I'm not sure what the technical term is for this). It uses the name that is sent over the network to find the corrosponding GameObject and creates a PhotonView on that object, with a ViewID that is the same as the one sent over the network. Sorry if I explained this poorly. Anyways, when the master client runs this, everything works fine. But the weird thing is that when a non-master client runs this, I get the following warning. Received OnSerialization for view ID XXXX. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined What is weird is that the warning doesn't appear at all on the non-master clients. It only appears on the master client when a non-master client tries to run through this "process". What I also find strange is that it seems to be stopping SharedInfo from reading anything from the stream on the master client (as I found out by putting a debug.log in the start of if (stream.isreading), and seeing that the debug.log never showed up in the console). Again, I'm sorry if this is explained poorly. But does anybody have any ideas as to why this might be happening?

Grab information about players BEFORE entering a room PUN 2

$
0
0
Hey all, So I am trying to implement this dynamic matchmaking system where the player doesn't interact with it at all. Basically I want implement a system when the player connects to the master server they are given a choice to host or join a game. If the player clicks on join, in stead of prompted to a list of rooms currently active, the game checks the player's save game, sees where the position they were last at and then picks a room where the host has a current position nearby the player's saved position. Is this possible? Can I get information of players in a game without connecting to the room? How can I do that? Thanks.

Problem with PhotonPlayer

$
0
0
Hello! I have a problem as stated in the title. I'm using void OnPhotonPlayerConnected(PhotonPlayer player) {}, but I get an error saying that PhotonPlayer could not be found. Thank you beforehand.

Cannot connect to MasterServer on wifi network

$
0
0
Up until this morning I have been able to connect to master server and test my game just fine on both my computer and test device. Now when I try to connect using my home wifi network it just hangs on ConnectingToMasterServer and ultimately times out. When I turn off wifi and use my cellular data everything works. Any idea what might be happening? I have not made any changes to my game since this started happening and my wifi seems to be working fine otherwise. Appreciate any insight.

Sequence for joining lobby/room

$
0
0
Could someone please advise or point me to an article (looked at Sky Arena, etc) on the basic workflow when using lobbies/rooms? The info is fragmented and a bit confusing :-(. Lot of stuff about joining rooms, listing players and all the callbacks - but HOW do they fit together? For the simplest case: I have two maps, the players pick one and hit "play", wait until 5 players (including themselves) get matched and are ready to go, the level loads (on ALL clients - i.e. wait until the slowest machine has finished loading), 10 second countdown, game begins for everyone. Question is: Where do they "wait" (is that in the lobby or in the room)? When do I JoinOrCreate the room? When do I load the level? Does the room have to be "JoinOrCreated" by at least one player before others see there's a room to join (with the room property "mapname" (or "mn" as recommended) exposed to the lobby for matchmaking)? Thanks for any help!

What exactly happens when reached CCU limit?

$
0
0
Hi, Sorry if this is duplicate (pretty sure) but I counldn't find my answer. So I'm using 100 CCU currently, What I'm curious about is what happens to 101 CCU? Can 101 CCU connect to lobby? or can 101 CCU "only" connect to lobby and not the room and if attempts to join the room OnPhotonMaxCccuReached() is called? I'm trying to figure out a way to handle the situation gracefully. Curious, curious

2 Person multiplayer (Help: Camera issue)

$
0
0
Hey I've been struggling to create a simple 1 vs 1 game. I've managed to do get both player join the same room and launch the scene. After that I've also managed to spawn 2 players each on their side. The part that bugs me is setting up the camera for each player so they can see from their own camera. The player prefab has a camera included So far in the code part i used the PhotonView.isMine to check which one i own and then i checked if PhotonView.isMine isn't mine then disable the camera. But that didn't seem to do what i want it to do. Can anyone point me in the right direction? Any help is really appreciated! :)
Viewing all 8947 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>