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

Rejoin room bug PUN2

$
0
0
So i have the following issue: i create a room(player ttl=60 secs) , i join one player(A used to keep the room alive when player B disconnects) and instantiate it's character, then another player(B the one who disconnects) and instantiate its character, when player B disconnects due to internet issues(disable adapter) i call ReconnectAndRejoin which successfully rejoins the room(so far so good each player have it s own character), now disconnect player B again and rejoins at this moment player B will have two characters, each time i disconnect player B and reconnect it the number of B characters duplicates (1,2,4,8 ...). The behaviour i expect is when disconnected and reconnected player B should have one character no matter how manny times i disconnect and reconnect to the same room. This problem can be reproduced with the demo slot racer too with a little change to OnJoinedInstantiate.cs after the prefab instantiation from the provided list make shure to null the list so it won't call instantiate every time you rejoin the room, now if you repeat the steps i sayd after each disconnect and reconnect you will have 1,2,4 ... controllers Does anyone have any idea how to fix this??

Cross-Platform Gaming

$
0
0
I am currently developing a game that uses Photon Pun and Realtime. However, I have hit a roadblock in my development process. I have tested the game on my laptop (Macbook Pro) and played with a few friends of mine who also run OSX. But when I try to create/join a room using a Windows computer, I cannot see the room on the other operating system (on my Mac). I developed this game in WebGL to be cross-platform and run on Chrome.

I'm not sure if I need to edit something in the PhotonSettings page or in my code if you need to look at anything lmk and I'll reply back here asap.

Thanks for the help,
Het

PUN 2 event got registered even though different App ID was used

$
0
0
Hello,

I have experienced a strange behavior in my project which uses PUN2. I have one app ID for the production version of the project (which is built and used on some PCs) and a completely different ID (even though it is on the same account) which is used while developing. Recently I triggered action in my development environment and the PUNRPC event got registered in our production setup EVEN THOUGH IT USES DIFFERENT APP ID. The PUNRPC method looks like this:

[PunRPC]
private void MethodName(String someValue)
{
foreach (Transform child in transform)
{
DoSomething();
}
someVariable= true;
someOtherVariable= false;
}

and I call it like this:

photonView.RPC("MethodName", RpcTarget.AllBuffered, someValue);

(I use RpcTarget.AllBuffered because it is essential that the event gets registered by the players that join later)

How is this possible? Is there a way to safely separate our production from development, so that the development process doesn't disturb our production and we can all work at the same time?

Any help would be much appreciated, we are really in need of a solution.

Thanks to everyone in advance!
BD

photonView.IsSceneView returns true after ownership has been transferred to player

$
0
0
Hello,

I am using the following code to transfer the ownership of a photonview to a player when he connects.
public class PlayerConnection : MonoBehaviourPunCallbacks
{
    public static bool OwnsPhotonView = false;

    private void Start()
    {        
        if (!OwnsPhotonView && this.photonView.IsSceneView)
        {
            photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
            OwnsPhotonView = true;
        }
    }
}

When the master client starts the room, he naturally takes ownership of the photonView. The problem is that when another client joins the room, the value of IsSceneView is true, and they then take back the ownership for themselves.

How can I stop that and make sure it's "first come first served"?

Transfer ownership OnApplicationPause in Unity

$
0
0
I have one network scene game object that I can transfer the ownership of. Whoever is the owner of this object, which I check with photonView.isMine, has the control over the UI of the game (it's a turn-based card game). Everything works fine and as expected except in some edge cases. For example, I want to gracefully handle ReconnectAndRejoin() on mobile devices. Right now, if the application loses focus I call Photon.Disconnect() and I call ReconnectAndRejoin() after application resumes, which works fine. The problem is, if I am the owner of this Photon game object and my application loses focus (pauses by going into the background), how can I ensure that the ownership is transferred to someone else before my application disconnect and pauses? A coroutine wouldn't work because everything gets paused.
Any suggestions? Any help would be greatly appreciated.

[PUN2] SteamVR/OpenVR cameraRig issues

$
0
0
Hello,

We are trying to port an existing SteamVR/OpenVR game to multiplayer. The issue we are facing is that we seem unable to let PUN use the correct camera when the player connects. The camera follows one player, the players who joins the last. We wants the camera to follow the correct player, not the last player. We read numerous threads on different fora, no one gives us the solution.

Somebody has any ideas?

PlayerNumbering script issue

$
0
0
hi,

I have an issue with using the PlayerNumbering script. I have attached it normally, but when I call the function p.getPlayerNumber(), I get indexes of first player to be 0 and second player to be -1.
Although in the gameobject it seems to show correct numbering "1,2"
playernumbering.png
So apparently from the image, it is the PlayerID i need to access ? Why does the numbering of player Index appears to be 0 and -1?

Issue with Photon View in Unity.

$
0
0
In Update function for the nonlocal player it never gets past if(PhotonView.IsMine). It gets past it every time for the local player. The script with the Update function is called PhotonPlayer and it is on a object instantiated from the Photon Room Script. I will put both down below.

public class PhotonPlayer : MonoBehaviour
{


private PhotonView PV;
//private PhotonView pv;

public GameObject myAvatar;
public int myTeam;

private string myName;

// Start is called before the first frame update
void Start()
{
PV = GetComponent<PhotonView>();
//PV.ViewID = 2;
myName = PV.name;

PV.RPC("RPC_GetTeam", RpcTarget.MasterClient);
//PV.RPC("RPC_SyncHeads", RpcTarget.All, myName);
//RPC_GetTeam();





}

// Update is called once per frame
void Update()
{

if (myAvatar == null && myTeam != 0)
{
if (PV.IsMine)
{
if (myTeam == 1)
{
int spawnPicker = Random.Range(0, GameSetup.GS.spawnPointsTeamOne.Length);

//if (PV.IsMine)
//{
Debug.Log("team1" + myTeam);
myAvatar = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerAvatar"),
GameSetup.GS.spawnPointsTeamOne[spawnPicker].position, GameSetup.GS.spawnPointsTeamOne[spawnPicker].rotation, 0);
Debug.Log("myAvatar" + myAvatar);
//pv = myAvatar.GetComponent<PhotonView>();
//PhotonNetwork.AllocateViewID(pv);
//}
}
else
{
int spawnPicker = Random.Range(0, GameSetup.GS.spawnPointsTeamTwo.Length);
Debug.Log("team2" + myTeam);
//if (PV.IsMine)
//{

myAvatar = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerAvatar"),
GameSetup.GS.spawnPointsTeamTwo[spawnPicker].position, GameSetup.GS.spawnPointsTeamTwo[spawnPicker].rotation, 0);
//pv = myAvatar.GetComponent<PhotonView>();
//PhotonNetwork.AllocateViewID(pv);
//}
}
}
}

}



[PunRPC]
void RPC_GetTeam()
{
myTeam = GameSetup.GS.nextPlayersTeam;
Debug.Log("myTeam:" + myTeam);
GameSetup.GS.UpdateTeam();
PV.RPC("RPC_SentTeam", RpcTarget.OthersBuffered, myTeam);
//RPC_SentTeam(myTeam);
}

[PunRPC]
void RPC_SentTeam(int whichTeam)
{
myTeam = whichTeam;
}

[PunRPC]
void RPC_SyncHeads(string nameIn)
{
GameSetup.GS.playerNames[myTeam] = nameIn;
GameSetup.GS.playerNameTexts[myTeam].text = nameIn;
}
}

And Photon Room where I am instantiating the objects from. I am instantiating in the create player function at the bottom.

public class PhotonRoom : MonoBehaviourPunCallbacks, IInRoomCallbacks
{

public static PhotonRoom room;
private PhotonView PV;
private GameObject netwarkPlayer;
private PhotonView pv;

public bool isGameLoaded;
public int currentScene;

Player[] photonPlayers;
public int playersInRoom;
public int myNumberInRoom;

public int playerInGame;

private bool readyToCount;
private bool readyToStart;
public float startingTime;
private float lessThanMaxPlayers;
private float atMaxPlayer;
private float timeToStart;

private void Awake()
{
if(PhotonRoom.room == null)
{
PhotonRoom.room = this;
}
else
{
if(PhotonRoom.room != this)
{
Destroy(PhotonRoom.room.gameObject);
PhotonRoom.room = this;
}
}
DontDestroyOnLoad(this.gameObject);
}

public override void OnEnable()
{
base.OnEnable();
PhotonNetwork.AddCallbackTarget(this);
SceneManager.sceneLoaded += OnSceneFinishedLoading;
//SceneManager.sceneLoaded += OnSceneFinishedLoading;
//PhotonNetwork.CurrentRoom.IsOpen = false;
}

public override void OnDisable()
{
base.OnDisable();
PhotonNetwork.RemoveCallbackTarget(this);
SceneManager.sceneLoaded -= OnSceneFinishedLoading;
}

// Start is called before the first frame update
void Start()
{
PV = GetComponent<PhotonView>();
readyToCount = false;
readyToStart = false;
lessThanMaxPlayers = startingTime;
atMaxPlayer = 3;
timeToStart = startingTime;

}

// Update is called once per frame
void Update()
{
if(MultiPlayerSettings.multiplayerSetting.delayStart)
{
if(playersInRoom == 1)
{
RestartTimer();
}
if(!isGameLoaded)
{
if(readyToStart)
{
atMaxPlayer -= Time.deltaTime;
lessThanMaxPlayers = atMaxPlayer;
timeToStart = atMaxPlayer;
}
else if(readyToCount)
{
lessThanMaxPlayers -= Time.deltaTime;
timeToStart = lessThanMaxPlayers;
}
//Debug.Log("Display time to start to the players" + timeToStart);
if(timeToStart<= 0)
{
StartGame();
}
}
}
}

public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("We are now in a room");
photonPlayers = PhotonNetwork.PlayerList;
playersInRoom = photonPlayers.Length;
myNumberInRoom = playersInRoom;
PhotonNetwork.NickName = myNumberInRoom.ToString();
if(MultiPlayerSettings.multiplayerSetting.delayStart)
{
Debug.Log("Displayer players in room out of max players possible (" + playersInRoom + ":" + MultiPlayerSettings.multiplayerSetting.maxPlayers + ")");
if(playersInRoom > 1)
{
readyToCount = true;
}
if(playersInRoom == MultiPlayerSettings.multiplayerSetting.maxPlayers)
{
readyToStart = true;
if (!PhotonNetwork.IsMasterClient)
return;
PhotonNetwork.CurrentRoom.IsOpen = false;
}
}
else
{
StartGame();
}
}

public override void OnPlayerEnteredRoom(Player newPlayer)
{
base.OnPlayerEnteredRoom(newPlayer);
Debug.Log("A new player has joined the room");
photonPlayers = PhotonNetwork.PlayerList;
playersInRoom++;
if(MultiPlayerSettings.multiplayerSetting.delayStart)
{
Debug.Log("Displayer players in room out of max players possible (" + playersInRoom + ":" + MultiPlayerSettings.multiplayerSetting.maxPlayers + ")");
if(playersInRoom > 1)
{
readyToCount = true;
}
if(playersInRoom == MultiPlayerSettings.multiplayerSetting.maxPlayers)
{
readyToStart = true;
if (!PhotonNetwork.IsMasterClient)
return;
PhotonNetwork.CurrentRoom.IsOpen = false;
}
}
}

void StartGame()
{
isGameLoaded = true;
if (!PhotonNetwork.IsMasterClient)
return;
if(MultiPlayerSettings.multiplayerSetting.delayStart)
{
PhotonNetwork.CurrentRoom.IsOpen = false;
}
PhotonNetwork.LoadLevel(MultiPlayerSettings.multiplayerSetting.multiplayerScene);
}

void RestartTimer()
{
lessThanMaxPlayers = startingTime;
timeToStart = startingTime;
atMaxPlayer = 3;
readyToCount = false;
readyToStart = false;
}

void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
{
currentScene = scene.buildIndex;
if(currentScene == MultiPlayerSettings.multiplayerSetting.multiplayerScene)
{
isGameLoaded = true;

if(MultiPlayerSettings.multiplayerSetting.delayStart)
{

PV.RPC("RPC_LoadedGameScene", RpcTarget.MasterClient);

}
else
{
RPC_CreatePlayer();
/* if (PV.IsMine)
{
PV.RPC("RPC_CreatePlayer", RpcTarget.All);
}*/

}
}
}

[PunRPC]
private void RPC_LoadedGameScene()
{
playerInGame++;

if(playerInGame == PhotonNetwork.PlayerList.Length)
{

//RPC_CreatePlayer();
PV.RPC("RPC_CreatePlayer", RpcTarget.All);


}
}

[PunRPC]
private void RPC_CreatePlayer()
{
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PhotonNetworkPlayer"), transform.position, Quaternion.identity, 0);
//pv = netwarkPlayer.GetComponent<PhotonView>();
//PhotonNetwork.AllocateViewID(pv);

}

public override void OnPlayerLeftRoom(Player otherPlayer)
{
base.OnPlayerLeftRoom(otherPlayer);
Debug.Log(otherPlayer.NickName + "has left the game");
playersInRoom--;
}

}

AutoSyncLevel not working, only MC loads level

$
0
0
Hi there,

I currently have one main issue, and one minor issue.

First one is that calling PhotonNetwork.LoadLevel on Master Client is only working for the master. Everything with networking is working fine, the lobby, room creation, 2 players in level. But this piece of code is not loading level for both players:

PhotonNetwork.LoadLevel(1);

While debugging, I doublechecked:
?PhotonNetwork.AutomaticallySyncScene
true
?PhotonNetwork.IsMasterClient
true

What am I missing here??

Second less important is that I want to change Master Client when some wants to change level. So that every player can initiate this. This is also not working as expected and is not moving the Master Client:

public void ChangeScene(GameObject sender)
{
Player[] players = PhotonNetwork.PlayerList;
foreach (Player player in players)
{
if (player.IsLocal)
{
PhotonNetwork.SetMasterClient(player);
}
}

if (sender.name.Equals("VoxelScene"))
{
PhotonNetwork.LoadLevel(1);
}
else if (sender.name.Equals("FutureScene"))
{
PhotonNetwork.LoadLevel(2);
}

}

Thanks in advance for any suggestions!!

How to set a local variable by means of an RPC function? (PUN2)

$
0
0
Hi to everyone,
I'm using the PUN2 framework. Is there a way to change the value of a variable in a client (or in all the clients) script from another client by means of an RPC function? For example, let's suppose that an integer variable "intvalue" and an RPC function "RPC_ChageValue(int changeVal)" are defined in a C# script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;


public class PUN2_Class : MonoBehaviourPun
{
public int intvalue;

void Start()
{
intvalue = 0;
}


void Update()
{
if(photonView.IsMine)
{
if (Input.GetKeyUp("a"))
{
photonView.RPC("RPC_ChageValue()",RpcTarget.AllBufferedViaServer,Random.Range(0,10));
}
{

Debug.Log("intvalue in Update: " + intvalue);
}


[PunRPC]
RPC_ChageValue(int changeVal)
{
intvalue = changeVal;
Debug.Log("intvalue: in the RPC function " + intvalue);
}

}

the "RPC_ChageValue(int changeVal)" function is called when a client push the "a" button, but the value of the variable "intvalue" changes only in the client which calls the RPC function. In case of a client different from me calls the RPC function, If I debug "intvalue" in the RPC funtion I will see the updated value of "intvalue", but if I debug it in the "Update" function the variable hasn't the new value. It seems that it is not possible to store a value passed by means of an RPC funtion in a local variable as the "intvalue" one of the example. It is right? Is there a solution to this? For example, It is possibile to store the value in a variable which is defined in the server in order to a client can access to that variable during a match? Thank you!

Hi, how to prevent the same IP to enter more than 2 or 3 times to my game (web-based)?

$
0
0
The thing is, if a player can enter "n" times repeatedly to a game(web-based), and get a nickname, he or she can take all CCU, and block the game.

Player.NickName doesn't work for me

$
0
0
Player.NickName doesn't work for me, and that's the on used in the setup tutorial! Whjat do i do?
edit: here's the code that doesn't work:
public void OnPlayerLeftRoom( Player other  )
		{
			Debug.Log( "OnPlayerLeftRoom() " + [i]other.NickName[/i] ); // seen when other disconnects
                }

Unable to Sync RPC value to clients joining later

$
0
0
Hi,
As the title says, I'm unable to sync values on Clients Joining later i.e I send the RPC already and when a client joins it doesn't get buffered on its app.

Please note:
1. I am using RpcTarget.AllBuffered
2. The RPC gets sent on Click.

Here's my code:
    void Start()
    {
        testIF = GetComponent<TMP_InputField>();
        textTMP = GetComponent<TextMeshProUGUI>();
    }
    [PunRPC]
    public void testFunction( string testString)
    {
        textTMP.text = testString;
    }

    public void spawnBookmark()
    {
        PhotonView pv = GetComponent<PhotonView>();
        if (pv.IsMine)
        {
            pv.RPC("testFunction", RpcTarget.AllBuffered, testIF.text);
        }
    }
I am getting input from user on runtime and a assigned this function to button via inspector.

Important: The user (not master) gets the rpc when both have joined but RPC is not sent yet. But when the user joins later (after RPC is sent) it get the string send by rpc for a mili second before the original text appears again.

What am I doing wrong here any clues? I have just began with the RPC on Photon.

Any help would be appreciated.

Thanks in advance.

IPv6 for Unity iOS Exports

$
0
0
Apple now requires iOS apps to support pure IPv6 connections. We tested PUN v1.75 and it supports IPv6, including the "Best Region" setting. If you use the Photon Cloud, you only have to make sure your PUN version is up to date. If you run a Photon Server, you need to use a recent 4.x server.

Test All Builds

Unity's support for IPv6 begins with 5.3.4p4. They posted about adding IPv6 support. Several versions of Unity do not successfully support IPv6, so you should test each build. If you get a client-side error like this, your client needs an update; Connect() to 'x.x.x.x' failed: System.Net.Sockets.SocketException: Network is unreachable in a IPv6 network.

Test Procedure

Read "Test for IPv6 DNS64/NAT64 Compatibility Regularly" to learn how to test IPv6 support easily. We do this for PUN before release. Make sure there is not some other plugin failing!

Handling Rejections

We know that some apps got rejected, despite using PUN v1.75 or newer. If your app gets rejected, please get in touch with the Apple review team. Point out that you're using PUN and that we and you both tested the networkcode versus their own test procedures. Explicitly point to their own test-description page. Apple suggests:
If the iOS application is successful in working across the macOS NAT64 test environment, then the next step is to submit a bug report. We ask developers to use the Apple Developer Bug Report web page - http://bugreport.apple.com to submit the bug report. The bug report is to indicate that there is some compatibility issue between the app and the App Review test environment. In the bug report, the developer provides evidence that the iOS application worked successfully across the macOS NAT64 test environment by including a packet trace to show the success of the connection process. Note that the bug report is not an indication as to where the problem lies, but the fact that the iOS app works in the test environment and not in App Review is an indication that the app / App Review interaction needs further review. Once the bug report is submitted, there issue is then assigned to investigation by an App Review group. Once a bug report is assigned to App Review, the next thing is to follow up with the bug report by communication with App Review - “appreview@apple.com”. While the email inquiries may not always get a response - all of the correspondence is viewed.

Cloud and Server

The Photon Cloud can not provide public IPv6 addresses in the short term. However, Apple's requirement is only that clients can cope with IPv6 addresses in their network, if that provides "IP translation", as described in their article. For anyone using Photon Server (OnPremise), this means, you can likely continue to run it as IPv4 service. If you want to setup a true IPv6 server, we have some docs for that. Get Photon Unity Networking in the Asset Store.

How build for WebGL?

$
0
0
Sounding perhaps enough foolish, but when I build for WebGL (Unity 2019 latest) when I choose "development build" then after uploading to Heroku, it works fine, while if I build for production, I get error for ws, web sockets seem not working. Could you please let me know how to have ws working in prod build?

Avatar controls given to others when a user leaves.

$
0
0
I have a photon room setup, and after a user joins, they network instantiate an Avatar they control. Strangely, when a user leaves the room - most commonly via quitting the app or turning off the headset - their avatar isn't destroyed (it should be when they leave) and the next user in the player list takes control of their rotation.

I've been looking into ways to check if the controlling player still exists, and if not destroy it. Or having the master destroy the object if it still exists when a player leaves, but no luck so far.

Any suggestions?

Photon as server

$
0
0
Hello,

I've been following this tutorial image so that I can learn how to use and better understand Photon 2, so far so good. The tutorial is focused on batteroyale kind games, where we have game players connecting to a player server and so on... What i'm trying to understand is that if Photon 2 can be used the the server, for exemple, there is no client server, only the "master" server that players connect to. What I got so far is that Photon 2 has only a network that players use to serve and connect to each other... What I'm looking for is a server + network that players connect. Is it posible? Does photon has something like that?

Thanks in advance,
Yours,
Diogo

Managing Local multiplayer and Online Multiplayer

$
0
0
Hello All,

For a project I'm working on, which already has local (offline) multiplayer, I need to implement networking functionality. For this I'm using PUN. The networking part is not the problem here. After starting to work with the networking I found it difficult as to how to balance my scripts to work for both online and offline. For example, the player instantiation would work differently, but we would have the same basic player components.

I am not sure what would be a good way to keep the networking functionality in my scripts separate from the normal functionality as much as possible. I imagine that I would have to add checks in some scripts like:
photonView.IsMine
Which is not really ideal in my situation.

I was wondering if anyone here has any experience on this subject, or some best practices type of advice.

Thanks!

What does "Disconnects/h per peer" mean in the dashboard?

$
0
0
We are hitting max CCU of 470-480 users. We see that we are having max "Disconnects/h per peer" of 161. What does this mean? Is this bad?

Joining an already running room

$
0
0
I am trying to create a simple game, that will consist of up to 50 players in a single room. I've downloaded and configured the server, but all the examples included with the unity bundle only spawn the scene with the players from the start. There doesn't seem to be the ability to let people join an already created room.

Is it possible in PUN to allow people to join and leave a room, without restarting the scene or launching a new scene?
Viewing all 8947 articles
Browse latest View live


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