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

Waiting room : print and synch players

$
0
0
Hello everyone !

So i'm a beginner to Photon Unity Networking and I'm creating a multiplayer system inspired by Overwatch and LoL systems :smile:
When the players connect to photon, a menu appears with a "play" button. On clicking on this button, the player can chose custom properties for the game : game mod, game map, number of players ... and then can choose between create a room with these properties or enter in matchmaking with the same properties.
When the player choose to create a room, a new panel appears, showing him room properties.
That is the problem : I want to print infos of every players in this panel and, obviously, synchronise them ... but I don't know how to do this !

Any help would be really appreciate ! I can give you more details about my problem if needed

Thanks you really much ! :smile:

Having a lot of issues with custom room properties for the lobby

$
0
0
Hey all,

So I've been having a hell of a time trying to get custom lobby properties set up and working properly for my game. Here's the rundown:

I have two different gamemodes that I'd like to connect to using PhotonNetwork.JoinRandomRoom(customRoomProperties, x) For some reason, I can't seem to get this to work. I've looked over all of the relevant documentation and poured over as many forum posts as I could, but I still can't seem to grasp the concept.

Here's my relevant code. I have two seperate networked scenes. CreateRoom is called when a match is hosted, and has the actual game scene. Looking is called by a "in between" scene that looks for an open match.
CreateRoom:
void Start()
{

PhotonNetwork.ConnectUsingSettings("0.1");
PhotonNetwork.automaticallySyncScene = true;
PhotonVoiceNetwork.Connect();
PlayerCount = 0;

}

public void CreateNewRoom()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.isOpen = true;
roomOptions.isVisible = true;

roomOptions.customRoomPropertiesForLobby = new string[1] { "gameType" };
roomOptions.maxPlayers = 6;
PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default);

}
void OnJoinedLobby()
{
CreateNewRoom();
}
Looking
using UnityEngine;
using System.Collections;
using Photon;
using Hashtable = ExitGames.Client.Photon.Hashtable;
public class PhotonLooking : Photon.MonoBehaviour

{
//Hashtable for room props
private Hashtable expectedCustomRoomProperties;
void Awake()
{
PhotonNetwork.ConnectUsingSettings("0.1");
PhotonNetwork.automaticallySyncScene = true;
}
void OnJoinedLobby()
{
Debug.Log("Joined Lobby");
StartCoroutine(WaitToJoinComp());
}

void OnPhotonRandomJoinFailed()
{
Debug.Log("Didn't Connect to Random Room");
StartCoroutine(WaitToJoinComp());
}

IEnumerator WaitToJoinComp()
{
//Looping 3sec timer for checking for open matches

//I'm guessing it's an issue here. Unity makes me set a value after
//configuring the string.
expectedCustomRoomProperties = new Hashtable { {"gameType", 1} };
yield return new WaitForSeconds(3);
JoinRandom();
}

void JoinRandom()
{
//Join room with expected properties. This doesn't work.
PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 6);
}
}
Sorry for the giant wall of code, and thank you so much if you bothered to look through this and try to help me.

Room max player limit reach with only one player

$
0
0
Hello everyone,

We are having a strange issue. Our game have been using PUN for about 3 years and everything was working fine until last Friday. The issue, is the players are unable to join the room. We have a player vs player (one to one) game model so there can only be 2 players in the room. One player who challenges the other player creates a room with other player name like following:

PhotonNetwork.CreateRoom(opponent.name + "*" + player.name, true, true, 2, properties, null);

The other player is constantly searching if anyone have created a room with its name and once it finds the room it joins the room and the match begins. But recently something went wrong. The player who tries to join the already created room was unable to join the room. After exhaustive debugging and out logs we came to know that by the time the other player, when tries to join the already created room, there are already 2 players in the room and hence can not join. But on the other hand the player who created the room is constantly logging output that there is only one player in the room.

The thing here is to note that we never had any issue like this before for 3 years with the same code and we haven't changed any code. Also we had some AI bots running and all of a sudden they were not able to join the game because they could not join the room.

Can you please let me know what might have gone wrong due to which the player who creates the rooms says there is only one player in the room and the other player who is to join cant join because it sees that there are already 2 player in the room?

Thanks,
Abe

Moved: Getting response error!!

How to select a specific network player - photon unity networking

$
0
0
Hi guys. This is my first post at photonengine. Please excuse if i have posted this in the wrong section.
I have been working on unity for a few months now and have a basic understanding of the environment. Currently i am working on a multiplayer game and for that i am using Photon Unity Networking utility ( PUN intended :P ). This would be my first multiplayer game.
I have a room and a corresponding scene where all the players join and can roam around freely. What i want to do is to be able to touch/click on a player and start a battle with just that player ( I have the code for selecting objects using raycast and colliders but what that does is give me the object that i created locally using photon.instantiate to mimic the network players. )
The way i have decided on implementing this is to take myself and the target player to a different room ( battle room ) and load a new scene ( battle scene ) while the other players are still in the free roaming room / scene.

QUESTIONS:
(1) How can i select a specific network player and communicate with just that player to tell them that a match is about to start between that player and myself and make them join a different room with me?
(2) Does it make a difference if i load the battle scene before or after i join the battle room?
(3) How can i make the target player load the new scene and check over the network if their device has finished loading the new scene?


I AM a Photon illiterate ( maybe even a Unity illiterate ) so please excuse if i annoy you.

I shall appreciate all answers.

EDIT: Here is the code i am using:
(Selecting opponent through touch )
            if (Input.touchCount >= 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
touchStartPos = touch.position;
}
if (touch.phase == TouchPhase.Ended)
{
if (touch.position == touchStartPos)
{
Ray cursorRay = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(cursorRay, out hit, 1000.0f))
{
if (hit.transform.gameObject.tag == "opponent")
{
selectedOpponent = hit.transform.gameObject;
myObj = GameObject.FindGameObjectWithTag("MyObj");
string roomName = "" + myObj.gameObject.transform.name + selectedOpponent.gameObject.transform.name + (int) Random.Range(1,100) ;
myObj.GetComponent<PhotonView>().RPC("StartFight", PhotonTargets.All, myObj.GetComponent<PhotonView>().viewID.ToString(), selectedOpponent.GetComponent<PhotonView>().viewID.ToString(), roomName);
}
}
}
}
}
(StartFight RPC)

[PunRPC]
void StartFight( string pID , string oID , string roomName ) //pID = local player's viewID, oID = target player's viewID
{
foreach ( PhotonPlayer player in PhotonNetwork.playerList )
{
if (player.customProperties.ContainsValue(pID) )
{
PhotonNetwork.LeaveRoom();
PlayerPrefs.SetString("roomName", roomName);
StartCoroutine(newRoom(roomName));
}
else if ( player.customProperties.ContainsValue(oID) )
{
PhotonNetwork.LeaveRoom();
PlayerPrefs.SetString("roomName", roomName);
StartCoroutine(newRoom(roomName));
}
}
}
The issue here is that even though i am checking player's ID and only executing PhotonNetwork.LeaveRoom() for the player's whose ID is matched, it is making all the players leave the room.
(newRoom CoRoutine)

IEnumerator newRoom ( string roomName )
{
PhotonNetwork.LoadLevel("Teset_Scene4");
yield return null;
}
This function is called when the new scene is loaded, here is where i attempt to join a new room

void JoinFightRoom ( )
{
if (!(PhotonNetwork.connected))
{
PhotonNetwork.ConnectUsingSettings(Constants.VERSION); // Constants.VERSION = "v0.0.1"
}
else
{
string roomName = PlayerPrefs.GetString("roomName");
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 2 };
PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
}
}

The issue here is that it gives me the following error:
JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

Photon instantiate GameObject with public declare

$
0
0
Hi, all
I wanna ask if I instantiate GameObject on photon network, then the how to assign public declare things.
We know the photon instantiate prefab can't be assigned public things.
I only know using 1. find with tags 2. find with name after instantiate.
if there are else way to assign public declare by code?

Thanks!

Server in China Mainland or Hong Kong?

$
0
0
Hi, PUN team! I saw you added three regions in the latest update. Great job!

I'm wondering, are you planning to add more servers in Asia? I know we can use servers in Singapore and Tokyo, but the connections from China Mainland to them are not good - the ping is at least 100ms, and in peak hours it can be as high as 400ms.

I'm developing an online co-op game targeting Steam, and most of the players are in China. As you may know, in China the numbers of players AND devs on Steam have increased significantly in the last 12 months. I think setting up some servers for China region will be definitely helpful to bring PUN's great experience to both devs and players.

Unity Friends Functions

$
0
0
I am trying to retrieve the friends from a db which is working cause the table is being populated, and then populate a gui, i removed that code though, as i am debugging why im getting the following errors
 Operation failed: OperationResponse 222: ReturnCode: -2 (Missing value 1 (FindFriendsRequest.UserList)
). Parameters: {} Server: MasterServer
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1494)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)

FindFriends failed to apply the result, as a required value wasn't provided or the friend list length differed from result.
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1843)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)

Heres the actual code, ive been stumped for about a day, trying different ways and methods, if you have any tips please do tell me.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

public class Connection : Photon.MonoBehaviour
{

public bool AutoConnect = true;
public byte Version = 1;
private bool ConnectInUpdate = true;

public GameObject friendsLinePrefab;
public string[] friends;
public List<GameObject> friendLines = new List<GameObject>();
public int i;
public InputField userToAdd;

// Use this for initialization
void Start () {
PhotonNetwork.autoJoinLobby = false;
}

// Update is called once per frame
void Update () {
if (ConnectInUpdate && AutoConnect && !PhotonNetwork.connected)
{
ConnectInUpdate = false;
PhotonNetwork.ConnectUsingSettings(Version + "." + SceneManagerHelper.ActiveSceneBuildIndex);
PhotonNetwork.playerName = GameObject.FindGameObjectWithTag("AccountDetailsManager").GetComponent<AccountDetailsManager>().displayname;
}

if (friends.Length > 0 && PhotonNetwork.Friends == null)
{
}
}
public virtual void OnConnectedToMaster()
{
getFriends();
StartCoroutine(waitForGetFriend());
RoomOptions roomOptions = new RoomOptions();
TypedLobby roomType = new TypedLobby("myLobby", LobbyType.Default);
PhotonNetwork.JoinOrCreateRoom("Hub", roomOptions, roomType);
}

public virtual void OnJoinedLobby()
{
getFriends();
StartCoroutine(waitForGetFriend());
RoomOptions roomOptions = new RoomOptions();
TypedLobby roomType = new TypedLobby("myLobby", LobbyType.Default);
PhotonNetwork.JoinOrCreateRoom("Hub", roomOptions, roomType);
}
IEnumerator waitForGetFriend()
{
yield return friends;
}

public virtual void OnPhotonJoinFailed()
{
PhotonNetwork.CreateRoom("Hub");
}

public virtual void OnJoinedRoom ()
{
GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
GameObject newPlayerObject = PhotonNetwork.Instantiate("HUBPlayer", spawnPoints[Random.Range(0,spawnPoints.Length)].transform.position, Quaternion.identity, 0);
newPlayerObject.GetComponent<PlayerController>().camera = GameObject.FindGameObjectWithTag("PlayerCamera").transform;
newPlayerObject.GetComponent<PlayerController>().mmCamera = GameObject.FindGameObjectWithTag("MMCamera").transform;
}
// the following methods are implemented to give you some context. re-implement them as needed.

public void getFriends()
{
WWWForm form = new WWWForm();
form.AddField("username", GameObject.FindGameObjectWithTag("AccountDetailsManager").GetComponent<AccountDetailsManager>().username);
WWW w = new WWW("http://get.friends.url", form);
StartCoroutine(getFriendsFunc(w));
PhotonNetwork.FindFriends(friends);
}
IEnumerator getFriendsFunc(WWW w)
{
yield return w;
if (w.error == null)
{
if (w.text == "User doesnt have any friends.")
{
Debug.Log(w.text);
}
else
{
Debug.Log(w.text);
friends = w.text.Split(',');
}
}
else
{
Debug.Log("ERROR: " + w.error + "\n");
}
}

public void addFriendButtonFunc()
{
addFriend(userToAdd.text);
}

public void addFriend(string usertoadd)
{
WWWForm form = new WWWForm();
form.AddField("username", GameObject.FindGameObjectWithTag("AccountDetailsManager").GetComponent<AccountDetailsManager>().username);
form.AddField("usertoadd", usertoadd);
WWW w = new WWW("http://get.friends.url", form);
StartCoroutine(addFriendFunc(w));
}
IEnumerator addFriendFunc(WWW w)
{
yield return w;
if (w.error == null)
{
Debug.Log(w.text);
}
else
{
Debug.Log("ERROR: " + w.error + "\n");
}
}

public virtual void OnFailedToConnectToPhoton(DisconnectCause cause)
{
Debug.LogError("Cause: " + cause);
}
}

How do i use Photon networking message ,Enum for OnjoinedRoom for start the game?

$
0
0
How use Photon networking message onjoinedroom to begin the game, can i use delegate to do that?

Handling disconnects due to application pause or debugger

$
0
0
I am using PUN in a fairly simple way to replicate data between a pair of clients.

The session is being established using ConnectUsingSettings followed by JoinOrCreateRoom called from OnJoinedLobby.

At the moment I'm testing the system on Windows and Android.

When one of the clients is running on Android, and that client is paused (goes into background) the client pretty much always gets booted out of the session. How am I best to manage re-joining when the player unpauses? Is there any way to make it less likely to get booted?

Secondly, when I am using the PC and attempting to debug my application, once I've stopped the application with a breakpoint, the app will lose it's connection the next frame. Is there any way to prevent this or handle it better?

Thanks

Jules

GetRoomList Problems

$
0
0

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;

public class Connection : Photon.MonoBehaviour
{
// Dungeon Settings //
public string[] potprefabs;
public string[] chestprefabs;
public string dungeonPlayerPrefab;
// Hub Settings //
public string hubPlayerPrefab;
// Connection Settings //
public string Version = 1 + "." + SceneManagerHelper.ActiveSceneBuildIndex;

public string hubScene = "Hub";

void Start()
{
DontDestroyOnLoad(gameObject);
PhotonNetwork.autoJoinLobby = true;
}


void Update()
{
if (PhotonNetwork.connected == false)
{
PhotonNetwork.ConnectUsingSettings(Version);
}
}

void OnJoinedLobby()
{
Debug.Log("Joined Lobby, Attempting To Join Hub..");
}

void OnJoinedRoom()
{
Debug.Log("Joined Room " + PhotonNetwork.room.name);
}

void OnReceivedRoomListUpdate()
{
Debug.Log(PhotonNetwork.GetRoomList().Length);
}



}
This bit of code below is outputting 0 and i cant seem to find out why.. Is there a delay between the callabcks?


void OnReceivedRoomListUpdate()
{
Debug.Log(PhotonNetwork.GetRoomList().Length);
}

Integrating PUN cloud with own authoritative server.

$
0
0
Hi,

In our project we have a self hosted (non photon) server which handles persistent state and certain game logic.

My question is regarding the options available for the our server to communicate with the PUN cloud service, in order to be involved in game events in an authoritative way. I'll give two examples of what we are trying to acheive:

1. When a player joins a room, own-server should verify that the player has rights to join that room, otherwise join should be rejected.

In this case webhooks and PathJoin/GameJoin looked quite promising. (I.e. Photon would call our server when a player tried to join a room, and our server would have a chance to reject it). However, I read in another thread that " PathJoin cannot cancel join operation", so this seems impossible (if still the case).

2. Own-server should be able to send command to PUN cloud server to kick a particular player.

(I haven't found a possible approach for this yet)


Please could someone at photon advise on what might be the best approach for these requirements?

Thank you!

S

Are custom properties overwritten if I pass a new hashtable without older values?

$
0
0
Hi,

I have a quite simple question, and just as it says in the title, if I pass a new hashtable to my player's custom properties that don't include a property I set before, will it be overwritten and removed?

For example. Every time I open the game I give the player a random value. So I do:
PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "myValue", 1234 } });

Now, when my player joins a room they will get a few other properties, for example, like if they are ready to play.
PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "ready", false } });

Now when I've set a new property and didn't include the old "myValue" in this, is "myValue" gone or is it still there? Will I still be able to access "myValue" later in the game after this? If not, is there a way so I don't have to include every property I set to the player in every line when I need to set some properties?

I would test this myself but my game is in such a mess that I would take so much work to actually test this. :/

How to make a Lobby Scene

$
0
0
So I have been looking everywhere and I can't seem to find any instance of Photon or Unity being able to handle a Lobby Scene where when connected to the server, the UI shows all the available rooms that have been created. At best I can find some random connection setups but nothing that list off all the rooms. This is a good example of what I am talking about
I mean maybe not as complex with its information requirements. maybe just: Name of room, Number of players, If it's Password Protected (which is something I don't know how to do)

I think it has something to do with PhotonNetwork.GetRoomList which I know is an array but I can't seem to write it out to be used.

I tried PhotonNetwork.countOfRooms but even after telling the server to make multiple rooms it only counts 0.

If anyone has any ideas that would be helpful.

Massive Stall when PUN session is being established

$
0
0
I am using PUN in an Android application which is rendering graphics at 60 fps.

I'm connecting using ConnectUsingSettings and JoinOrCreateRoom (in OnJoinedLobby).

At some point during a successful connection process I get a massive stall, which significantly impacts the user's experience.

Is it expected? Is there any way to prevent this stall? Is it known what causes it? How might I approach finding out the cause if it is not expected?

Thanks

Jules

Photon Networking Messages : When a player is leaving the room

$
0
0
Hi there,

I've read a lot of topics, pdf and documentations but didn't find any function or clue about handling this specific case : when the player is currently leaving a room (not after he left ; OnLeftRoom(), not when other players notice that he disconnected ; OnPlayerDisconnected()).

Is it possible to define a custom photon event triggered by the user when he's currently leaving a room ? This event will be triggered before OnLeftRoom() and OnMasterSwitched() of course.

Thank you very much for your help.

The canvas gone after a refresh (Bug)

Instantiate error:

$
0
0
using UnityEngine;
using System.Collections;

public class Spawn : MonoBehaviour {


public GameObject Item;
private float Timer;

void Awake (){
Timer = Time.time + 10;
}

void Update (){
if (Timer < Time.time) {
PhotonNetwork.Instantiate(Item, transform.position, transform.rotation);
Timer = Time.time + 10;
}
}
}

??

I need to use variable GameObject.

error:


No overload for method "Instantiate" takes '3' arguments

Is CrossPlatform play supported on Console? (ie PS4 + PC)

$
0
0
Can anyone fill me in on the extent of support for PS4? I'm wondering if cross-platform play is supported from PC > PS4, and if that includes support for PSN Friends and NAT traversal.

I've asked the Unity team regarding UNET, and the response was basically that cross-platform play is not supported, because they use Sony's UDPP2P service, which gives them free nat traversal and other integration benefits:
Currently we provide an interface between NpToolkit PSN matching and UNET. This means you have to advantage of using PSN accounts, and other PSN features like invites and friends. By making use of UDPP2P protocol with the PSN matching we get NAT traversal included.

It has the disadvantage of restricting you to playing between sony platforms only. As this covers the vast majority of what developers require we felt this is a good comprise.

In order to player PS4 vs PC you'll need to use UNET native features for game hosting. You'll also have to mange NAT traversal yourself (both for PC and PS4). Also perhaps an managed server to handle interface with PSN accounts (an 'auth' server)

I'm not aware of any developers that have attempted this yet. While it is no small amount of work (compared to PS4 only solution), it certainly should be possible by ambitious developers with time and resources to invest.

Is this essentially the same situation with PUN?

MMO Game

$
0
0
Hello,
I want to create multiplayer game like slither.io & other ajgar.io it working with Photon Real time
but i need to Convert MMO game so all connected player in same room there might be more than 1000 player at a time so want i want to do crate a new server or photon provide any facilitates for it.
Viewing all 8947 articles
Browse latest View live


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