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

AllViaServer small delay

$
0
0
Hello guys ! I'm currently working on a multiplayer version of a game. I already have the room joining/listing working properly, and I'm having some trouble with the game mechanics.
In our game, the player must pickup items which he can upgrade in furnaces or workstations. During local play, no bugs happen. Only one item can be put inside a furnace and only one player can work on an item in a workstation at a time.
But in the on-line version, when two players used the same workstation at the same time, a glitch happened in which they would both use it and get stuck. To fix this, I changed almost all the object interactions to use the AllViaServer RPC option (they were using the All option before). This fixed the bug, however, there is a small delay (about 300ms) between the button being pressed and the interaction happening.
I imagined that, since the action travels to the server first, it would generate a small delay. But is there a way to reduce it substantially?
Other than sending the RPC to the master client (in which there would also be a delay), I see no other way of fixing this.

edit:
Player goes to a storage (which has a photon view) > player presses the button > storage instantiates an item using photon > item interacts with the player using an rpc (using all option) > player is now carrying the item

Player goes to the desired workstation > player presses the button to interact > the workstation sends an rpc to upgrade the item (using AllViaServer) > if the workstation is not being used, the player starts upgrading the item

Thanks for your time !

Photon wont start on older Android devices unless I restart after game install

$
0
0
Hi there,
I have a pretty weird and random issue. I'm trying to optimize my game so it works on older devices such as a Samsung Note 3. On the Note 3, when I first install the game, for some reason it won't connect to the Photon Cloud. If I restart my phone after the install, it works great, no issues at all. For now I found a work around where if I detect that Photon doesn't work, I give the player a message asking them to restart their phone. However I would like to solve this issue if possible. Any ideas at all why this could be happening? I'm pushing the game from my Unity Editor straight to the phone via a USB cable. I don't have a newer Android device to test this on unfortunately so I'm not sure if this is happening on older devices or all android ones either...

Thanks in advance for any suggestions!

QueueIncomingReliableWarning and GameObject.Find

$
0
0
Hey all, I would like some advice as to how to resolve this issue I am encountering:

Recently, I updated the game's code to have standard room joining and hosting (so player is in lobby, they can create a room to host or they can find a room to join and play).

When a player joins a game, whether host or player, they change scenes. One of the gameObjects that instantiates over network is the GameManager, and we're using the GM to find the various other gameObjects to make our game work.

It was all fine before I integrated the aforementioned dynamic room host/join. As of now, host can create their rooms, join, and all is well. However, if a player wants to join that room, they would go in, load, and for the lack of better words, almost complete the process of setting things up. The GM, using GameObject.Find for the various things, would find most but not all necessary gameObjects, which wasn't an issue before (and I know, this is probably the worst way of going about it but we're on a timeline and we're all about getting results first before optimization. :X)

In the console, I saw how the message QueueIncomingReliableWarning was popping up before the GM would awake. I've encountered the message time and again but it never did much before besides some framerate drops. However, I am beginning to suspect that it could be interfering with the GM in its process of finding the gameObjects now. Am I wrong?

This wasn't an issue for the players before I updated the code. As reference, how we were loading in was ConnectingToMaster -> player is in a scene, they pick an avatar and join game -> JoinLobby() -> OnJoinLobby() -> CreateOrJoinRoom(...) -> OnJoinRoom...

As you can see, I had to update the code so it wasn't that flow that preventing room listings and whatnot. We weren't even in the lobby at all. However, for whatever reason, the game was working fine off of that. Now that the flow is this:
ConnectingToMaster -> JoinLobby() -> OnJoinLobby() -> player is in a scene, they pick an avatar, choose to host or join, overhead coroutine cycle checking for room lists and availability -> CreateRoom if host, JoinRoom is player -> OnJoinRoom...

Players can join the room but some things would be janky.

My apologies for the long post, I wanted to make sure it was as detailed as possible. If anyone can lend some advice for what I should be looking for in regards to why the GM is not finding some of the gameObjects anymore after changing how the players are joining rooms, please do tell. I spent the majority of the last two days on this. Best and cheers,

Andy

Two Newbie questions

$
0
0
I asked in Unity forums but no one seems to be answering. I want to ask 2 questions related to PUN:

1) Hello, new to Networking, my first multiplayer game, a top-down 2D shmup arena.
I used PUN and everything runned smoothly eventually in my first attemps and tests except a thing. The shmup ships move around and one sees another move smoothly. But a small, a bit lag seems to be created as the game runs and gets bigger and bigger over time. This leads to jumps in the "other" ships' movement about at the 5 minute mark.
I live in Greece and set up the preferences to EU Photon Server. I also tested this to different connections, so I don't think it is a "my" connection problem.
The player observes only one script nested to the "other" ships gameobjects which is the following:
using UnityEngine;
using System.Collections;

public class NetworkCharacter : Photon.MonoBehaviour {

Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;


void Start () {

}


void Update () {
if( photonView.isMine ) {

}
else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {


stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {


realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
}

}
}

There are of course 2 other scripts in the ship, one for movement and rotation, and one for camera, but those are not observed.
Anybody has an idea?



2) Furthermore, are there series of up to date video tutorials that explain all the features of PUN? There are some in in Photon website as links, but they are from like 2014. Should I trust them?

PUN having a weird issue / bug

$
0
0
Good day, I'm currently having a problem about Photon. I already created the game and it's almost ready to launch. The problema is when I test my game on one laptop (Two clients opened in one laptop) It's working really fine. The position and rotation are the same, but when I test my game to one pc to another pc (one client each pc) the position and rotation are not the same. Like the other client is going to other places, and not syncing with the other pc, but like I said when it's on one laptop tested (two clients opened) it's working really fine. Any help?

Variable doesn't sync using RPC

$
0
0
I'm building a multiplayer game that needs to know how many players are in the game to assign the player number when someone new joins, spawn him in a certain place, etc.

This is how the Inspector of the gameManager looks like:



Those are the PunRPC methods that I call to get and set the variable of players on the NetworkPlayerManager class:

public int numPlayer;

[PunRPC]
public void GetPlayers()
{
GetComponent().setNumOfPlayers(numPlayer);
}

[PunRPC]
public void SetPlayers(int num)
{
numPlayer = num;
}



And her's how I call them when a new player is Instantiated on the GameManager class:

GetComponent().RPC("GetPlayers", PhotonTargets.AllViaServer);

m_Tanks.m_Instance =
PhotonNetwork.Instantiate("Tank", m_Spawns[numOfPlayers].position, m_Spawns[numOfPlayers].rotation,0) as GameObject;

numOfPlayers += 1;

m_Tanks.m_PlayerNumber = numOfPlayers;

GetComponent().RPC("SetPlayers", PhotonTargets.AllViaServer, numOfPlayers);


Using this method, once one player enters the game, the value stays in 1 and it doesn't change. It's like the variable doesn't sync, and for every new Instance, it's set to be the player 1.

I've tried to use OnPhotonSerializeView too to make the sync, but it didn't do nothing using:

if (stream.isWriting)
{
stream.SendNext(numPlayer);
}
else
{
numPlayer = (int)stream.ReceiveNext();
}


I think that I have an error of concept on how to synchronise variables. I've searched and looked, but I haven't find what I'm doing wrong.

Photon Instantiating previously loaded objects when I use ReJoinRoom

$
0
0
I am trying to rejoin a room (to support the case of the network connection getting cut when when going to the home screen on an iPhone)

I am creating my room like this:

PhotonNetwork.UsePrefabCache= true;

var room_options = new RoomOptions();
room_options.PlayerTtl = 5 * 1000;
room_options.EmptyRoomTtl = 5 * 1000;
<b class="Bold">room_options.CleanupCacheOnLeave = false;</b>
room_options.PublishUserId = true;
room_options.MaxPlayers = 8;

PhotonNetwork.JoinOrCreateRoom(room_name,room_options,new TypedLobby("SQL_LOBBY",LobbyType.SqlLobby));
When I use ReJoinRoom after a disconnection it seems all of my PhotonNetwork instantiated objects ( which are still loaded into memory due to room_options.CleanupCacheOnLeave = false ) are trying to be instantiated again and produces many PhotonView ID duplicate found errors. Here is the stack:
PhotonView ID duplicate found: 2. New: View (0)2 on obj_hdqr_0_0_00_00(Clone) (scene) old: View (0)2 on obj_hdqr_0_0_00_00(Clone) (scene). Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RegisterPhotonView(PhotonView) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3410)
PhotonView:Awake() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:269)
UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
NetworkingPeer:DoInstantiate(Hashtable, PhotonPlayer, GameObject) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3088)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2409)
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:157)
I am using PUN v1.80.

I am using on premise server and am not using PhotonNetwork.AuthValues

Am I missing a room setting or something to get this behaviour working correctly? I notice the exceptions are not created if CleanupCacheOnLeave = true but in the event of a short network disruption when the scene is still loaded and set up correctly in memory I would like to used the cached objects and views as is.

Thank you

Newbie 2 questions

$
0
0
I asked in Unity forums but no one seems to be answering. I want to ask 2 questions related to PUN:

1) Hello, new to Networking, my first multiplayer game, a top-down 2D shmup arena.
I used PUN and everything runned smoothly eventually in my first attemps and tests except a thing. The shmup ships move around and one sees another move smoothly. But a small, a bit lag seems to be created as the game runs and gets bigger and bigger over time. This leads to jumps in the "other" ships' movement about at the 5 minute mark.
I live in Greece and set up the preferences to EU Photon Server. I also tested this to different connections, so I don't think it is a "my" connection problem.
The player observes only one script nested to the "other" ships gameobjects which is the following:
  using UnityEngine;
using System.Collections;

public class NetworkCharacter : Photon.MonoBehaviour {

Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;


void Start () {

}


void Update () {
if( photonView.isMine ) {

}
else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {


stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {


realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
}

}
}
There are of course 2 other scripts in the ship, one for movement and rotation, and one for camera, but those are not observed.
Anybody has an idea?



2) Furthermore, are there series of up to date video tutorials that explain all the features of PUN? There are some in in Photon website as links, but they are from like 2014. Should I trust them?



Variable doesn't sync using PunRPC call

$
0
0
Hi, I'm trying to Sync the number of players of my game, so I can set them into a position and so one. I use RPC calls to control it better and be more efficient.
Here's how's the inspector of the game maganer:



On the NetworkPlayersManager I have this code for RPC calls:

public int numPlayer;

[PunRPC]
public void GetPlayers()
{
GetComponent().setNumOfPlayers(numPlayer);
}

[PunRPC]
public void SetPlayers(int num)
{
numPlayer = num;
}


And then I call them on the GameManager code like this:

GetComponent().RPC("GetPlayers", PhotonTargets.AllBuffered);

m_Tanks.m_Instance =
PhotonNetwork.Instantiate("Tank", m_Spawns[numOfPlayers].position, m_Spawns[numOfPlayers].rotation,0) as GameObject;

numOfPlayers += 1;

m_Tanks.m_PlayerNumber = numOfPlayers;

GetComponent().RPC("SetPlayers", PhotonTargets.AllBuffered, numOfPlayers);



The number of players always is 1. It's like the info doesn't sync and every new instance of the player starts at 0 and identifies them as player 1.

OnConnectedToMaster not called when Auto-Join Lobby setting is checked

$
0
0
How to reproduce:

On the PhotonServerSettings ScriptableObject, enable Auto-Join Lobby.
Create a new MonoBehaviour and implement the Photon messages.
On Start, invoke PhotonNetwork.ConnectUsingSettings().
OnConnectedToMaster will not be invoked.
Uncheck Auto-Join lobby and try again. This time it will be invoked.

Btw the same tolken, is it possible to join a room without first joining a lobby?

PhotonView stating method doesn't have proper number of arguments.

$
0
0
I have many other [PunRPC] calls which work just fine. After modifying an existing call, it breaks. I'm not sure what's causing this. I went to the PhotonServerSettings and can see that RPC_AllPlayersInGameboard is in the Rpc list; I have tried clicking refresh.

I receive the following error:
PhotonView with ID 2 has no method "RPC_AllPlayersInGameboard" that takes 1 argument(s): PhotonPlayer

method:
[PunRPC]
private void RPC_AllPlayersInGameboard(PhotonPlayer[] players)
caller:
photonView.RPC("RPC_AllPlayersInGameboard", PhotonTargets.All, PhotonNetwork.playerList);

PhotonNetwork.Disconnect() Problem

$
0
0
Hi.
I have a problem. I wanna load a level after getting diconnected from a room. But i can't do this
PhotonNetwork.Disconnect();
Application.Loadlevel();
Because if i do that, i doesn't disconnect fast enough and loads the level without getting disconnected. I also can't use this
void OnPhotonPlayerDisconnected()
{
    Application.Loadlevel();
}
Since that message only gets send to people inside the room that isn't disconnected. So i'm lost and can't find a logic to this one. Could use a timer, but if people lag or there is a server lag or something, that isn't gonna work. How could i make this?

Can't reference the hashtable

$
0
0
Need some help referencing a Hashtable I created in the awake function:

So in the Awake function I am trying to set up the custom properties:


public void Awake(){
ExitGames.Client.Photon.Hashtable props = new ExitGames.Client.Photon.Hashtable();
props.Add("score", 0);
PhotonNetwork.player.SetCustomProperties(props);
}



Later, in a function where the player has gotten a point added to his score, I have:

[code]
public void getPoint(){
score = (int)PhotonNetwork.player.CustomProperties["score"];
score++;
PhotonNetwork.player.CustomProperties ["score"] = score;
PhotonNetwork.player.SetCustomProperties(props);
}
[/code]

I get the following error: The name `props' does not exist in the current context

Anyone know how I can reference the props Hashtable?


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 might have to update.

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.

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 netcode versus their own test procedures.

Explicitly point to their own test-description page. If our tests fail and theirs doesn't, we have to figure out what we have to test! At the moment, it's unclear.

Cloud and Server

The Photon Cloud itself will not be directly available via IPv6 in the short term. Apple's requirement is that clients can cope with IPv6 addresses, if there is a "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.

Questions about the Photon Cloud script "PhotonStatsGui".

$
0
0
http://imgur.com/pqMSESa
After the script collects data during one second, I display the data in GUI and reset the traffic - PhotonNetwork.networkingPeer.TrafficStatsReset ();
In the room there are two players and 20 bots.

1) I send Vector3 movement of 20 bots - script CubeLerp,OnPhotonSerializeView. Why it takes 6000 bytes? Veсtor3 -16 * 200 bytes (10 positions per second * 20 bots) = 3200 bytes!
2) What are the: In * 18, TotalPacketCount = 10, TotalCommnadsInPackets = 20? It is not clear, how does this relate to the number of packages. Logically, there should be 200 messages in a second from bot's positions (the Photon Cloud documentation says that movement packages combine in a unique way). How do the combine? What is the formula for calculating? What is the difference between the "package command" and "package"?

Show user level with Photon

$
0
0
Well, how wonderful. Im using Photon. Okay i have a playerprefs for the playerlevel. I have also a mask and a grid were you can see all joined players included there level. So when a player joined the room. A UI obj is instantiated within 2 objects as child. (Playername and playerlevel)
Playername is already working but the playerlevel is a great mess since its info comes from a playerprefs. How can I sync the playerlevel for all joined people?

public Text Playerlevel;

void Start ()
{
Playerlevel.text = "level " + Playerprefs.GetFloat ("Playerlvl");
}

void Update ()
{
if (photonView.isMine)
....
}

It drives me crazy. Playerlevel.text is the child of the "roommask"
Please help. This is a very great problem.

Assigning a Veriable to a photon-instnsiated object? .GetComponent?

$
0
0
Hi gang I'm using Photon instantiate to instantiate my Bombers, s their a way to use .getcomponent to set a variable on the Bombers Script?
I know you can ();
Bomber.Target = Target;

with regular instantiate, is their a way to do this with Photon.insnasiate?

Setting string[]{} means the client expects no plugin to be setup.

$
0
0
CustomRoomPropertiesForLobby()
What plugin ?
How to use it?
Thanks for help.

I have a prob for join random room

$
0
0
I set the customprops.I get the room's customProps in room is right, but it is empty in outside.

print(inroom):Room: '00000000000000E0' visible,open 1/6 players. customProps: {level1=1}

print(out):Room: '00000000000000E0' visible,open 1/6 players. customProps: {}

So player can‘t join in room.
error:Operation failed: OperationResponse 225: ReturnCode: 32760 (No match found). Parameters: {}

Please for hlep.Thank you very much.

Optimize Messages per second

$
0
0
As in the documentation messages per second are calculated the following way:
That is, for 30 players / room:
30 players x (1 incoming request + 1 outgoing response + 29 events to other players) x 4 msg/s
30 x (1 + 1+ 29) x 4 = 30 x 31 x 4 = 3720 msg/s
==> This is way above the 500 msg/s limit and also one client will receive about 120 packets from other clients and maybe cannot handle that much!

1.) So why not pack all movements into one array?
Is there a possibility the photon server can pack all user movements into one array so that every user gets only one message from the server with all user data and not messages from all other clients in the room?

As in the above example the optimized version would look like:
30 players x (1 incoming request + 1 outgoing response) x 4 msg/s
30 x 2 x 4 = 240 msg/s
This looks good from the server side and also the client only has to handle 4 ingoing and outgoing messages to the server.

2.) Cull Area
I have seen the demo example with the cull area. My question is where can I set the updates to either 1 per second or 0, that means not rendered at all for players more far away
With cull area it may be possible to reduce the amount to 1/10 so the above example will come below 500 msg/s.

3.) No updates when no movements
This is already possible with the Observe option UreliableOnChange, is this right? This should also save about 70% of traffic but depends on game how often the players are idle.

4.) Updates per second
With cull are active I see the possibility to reduce the traffic much, but what happens if all 30 players meet at one point? Then maybe we have to lower the updates per second to 1-4. This will get very laggy but it should not happen so often. Best would be imho if there would be an option that the photon server handles the updates per second automatically to keep below the 500 msg/s.
Viewing all 8947 articles
Browse latest View live


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