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

It takes time when I re-enter the same game-room

$
0
0
I am developing a Unity game app with PUN.
My problem is... at first, two players are OK with getting into the game. However, when one of them gets out (using PhotonNetwork.LeaveRoom()) and tries to re-enter the same game-room (using PhotonNetwork.JoinRoom(room name)), it takes a while. And it takes longer as you try again. Sometimes it doesn't even move at all.
Please help me. The source code about entering the game_room is here...
I am using Unity 2017.3.1f1. Thanks.
-------------------------------------------------------------
public void PlayGame() {
foreach(RoomInfo ri in PhotonNetwork.GetRoomList()) {
if (ri.PlayerCount < ri.MaxPlayers) {
PhotonNetwork.JoinRoom(ri.Name);
break;
}
}
}

void OnJoinedRoom() {
...
StartCoroutine(Battle_Scene());
}

IEnumerator LoadBattleField() {
PhotonNetwork.isMessageQueueRunning = false;
AsyncOperation ao = SceneManager.LoadSceneAsync("Battle_Scene");
yield return ao;
}



Photon RaiseEvent and returning data from PlayFab CloudScript

$
0
0
Hi,
I have a game linked to PlayFab that uses RaiseEvent with ForwardToWebhook true, and it correctly calls the Cloudscript.
My question is, how can we correctly return data from the CloudScript call?

I tried to follow your example here: https://community.playfab.com/questions/10944/playfab-photon-webhooks-return-value.html
which seemed to work initially but has since broken itself.

The steps I do:
1) C#
PhotonNetwork.RaiseEvent(23, jsonObject, true, new RaiseEventOptions() { ForwardToWebhook = true, Encrypt = true, Receivers = ReceiverGroup.Others });

2) CloudScript
handlers.RoomEventRaised = function(args)
{
    if (args.EvCode == 23)
    {
        if (playerWinningChallenge > 0)
        {
        	return { 'PlayerWinningChallenge' : playerWinningChallenge };
        }
    }
}
3) C#
   void OnEventCall(byte eventCode, object content, int senderId)
    {
            string searchString = "PlayerWinningChallenge=";
            int indexOf = contentString.IndexOf(searchString);
            if (indexOf >= 0)
            {
                // Parse the data
            }
    }
Am I missing something here? It now seems to be calling OnEventCall() for all my events now (i.e. for totally unrelated events that don't return anything), and never hitting the data parsing line.

I'm at a bit of a loss, since the CloudScript is a bit of an undebuggable blackbox, and returning data seems like an undocumented behaviour.

Thank you for your time,
Duncan

Set interest groups in RPC.

$
0
0
Is there a way to set which interest groups receive an RPC?

For example in my game I have a sniper rifle, obviously I want the sniper rifle to shoot further than my shotgun. So while I fire my Sniper shot I would want to use different groups to be able to receive the sniper shot then I would use for my shotgun shot.

Maybe I'm going about this idea wrong and there is something better all together to solver this problem?

Please I need Help with my setFloor system

$
0
0
Hi I'm green in unity and too in PUN :) I'm trying that when a client change of floor in the map, this change only affect this client and not at all clients.

I'm using a script in a Trigger2D to send a value(CambiaPiso.cs) to setFloor(int i)(MapManager.cs), when setFLoor receive a value, this set activeself of floors in the map.
I'm tried with RPC but I could not achieve it :/
here Here is a demonstration of how works.... but when 1 player change of floor.... all change with him.
https://youtube.com/watch?v=K-uZyPJMjl4&feature=youtu.be

I need this to be done only on the client that walks through the trigger and not at all . Someone can help me to make this? :) (The comments are some pieces of my lasts tries)

Inspesctor of player prefab:
[img]https://preview.ibb.co/cN7Ntn/1.png [/img]

CambiaPiso.cs (the trigger2D(CambiaPisos) in the floor have this script)
https://preview.ibb.co/eJ4tYn/2.png

using System.Collections; using System.Collections.Generic; using UnityEngine; public class CambiaPiso : MonoBehaviour { // Use this for initialization [SerializeField] MapManager mapManager; public int numeroPiso; //PhotonView photonView; /*PhotonView id = gameObject.GetComponent<PhotonView> ().viewID; PhotonView a =PhotonView.RPC("setFloor", RPCMode.Server, id);*/ void Start () { } // Update is called once per frame void Update () { } void OnTriggerEnter2D(Collider2D col) { //photonView = col.gameObject.GetComponent<PhotonView> (); if (col.gameObject.tag == "Player") { if (mapManager.currentFloor == numeroPiso) { //photonView.RPC ("setFloor", PhotonTargets.MasterClient, numeroPiso-1); mapManager.setFloor (numeroPiso - 1); } else { //photonView.RPC ("setFloor", PhotonTargets.MasterClient, numeroPiso); mapManager.setFloor (numeroPiso); } } } }

CambiaPisos Inspector (the trigger2D in floor)
https://preview.ibb.co/grXmm7/4.png

MapManager.cs
https://preview.ibb.co/nrY967/3.png

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MapManager : MonoBehaviour { public int currentFloor; [SerializeField] private GameObject currentMap; public Text txt; public static MapManager MP; //PhotonView view; void Awake() { MP = this; } void Start () { currentFloor = 0; setFloor (currentFloor); //view = this.GetComponent<PhotonView> (); } // Update is called once per frame void Update () { txt.text = currentFloor.ToString (); } [PunRPC] public void setFloor(int i) { currentFloor = i; switch (i) { case 0: currentMap.transform.GetChild (0).gameObject.SetActive (true); currentMap.transform.GetChild (1).gameObject.SetActive (true); currentMap.transform.GetChild (2).gameObject.SetActive (false); currentMap.transform.GetChild (3).gameObject.SetActive (false); break; case 1: currentMap.transform.GetChild (0).gameObject.SetActive (true); currentMap.transform.GetChild (1).gameObject.SetActive (true); currentMap.transform.GetChild (2).gameObject.SetActive (true); currentMap.transform.GetChild (3).gameObject.SetActive (false); break; case 2: currentMap.transform.GetChild (0).gameObject.SetActive (true); currentMap.transform.GetChild (1).gameObject.SetActive (true); currentMap.transform.GetChild (2).gameObject.SetActive (true); currentMap.transform.GetChild (3).gameObject.SetActive (true); break; case 3: currentMap.transform.GetChild (0).gameObject.SetActive (true); currentMap.transform.GetChild (1).gameObject.SetActive (true); currentMap.transform.GetChild (2).gameObject.SetActive (true); currentMap.transform.GetChild (3).gameObject.SetActive (true); break; default: break; } } }
GameManager Inspector
https://preview.ibb.co/hK7rKS/5.png

Thanks in advance.

NullReferenceException: Object reference not set to an instance of an object

$
0
0
Well, after searching the Internet for this answer, I can not figure out how this is happening. I have seen forums discussing that you need to Instantiate the object, but I can not get my head wrapped around what the code needs to look like.
The idea is this: The player wants to launch a UAV (drone), and see the camera, that is on the drone, displayed on the monitor he is looking at, on the table, so that he can fly the drone around...
This is what I have at this point


<br /> using System.Collections; using System.Collections.Generic; using UnityEngine; public class DroneMonitor_Trigger_Script : Photon.MonoBehaviour { public GameObject Drone; public float Speed; public bool HaveWeEnteredTrigger = false; public Vector3 dir; //========================================================================= [PunRPC] public void MoveDrone(Vector3 direction) { Drone.transform.Translate(Vector3.up * Time.deltaTime * Speed); } //========================================================================= public void OnTriggerEnter(Collider other) { if(other.tag == "Player") { HaveWeEnteredTrigger = true; } } //========================================================================= // Update is called once per frame void Update () { if (Input.GetKey(KeyCode.Insert)) { if (HaveWeEnteredTrigger == true) { dir = Vector3.up; photonView.RPC("MoveDrone", PhotonTargets.MasterClient, dir); // The above line is what is generating the error... // NULLREFERENCEEXCEPTION: Object reference not set to an instance of an object. // DroneMonitor_Trigger_Script.Update() (at Assets/DroneMonitor_Trigger_Script.cs:39) } } <img src="http://www.carpatheous.com/DroneWithCamera.png" alt="" /> } }

System.Buffer.BlockCopy error in Fabric

$
0
0
Hello,

Capture

We have an issue with our mobile game, image above shows the error. 128 players effected by this 'Non-Fatal' exception,and its increasing slowly,Any chance to fix this issue? We are using Admob,Firebase,Facebook,PlayFab and Fabric plugins in our game,if it helps.

"OnConnectedToPhoton" and "OnConnectedToMaster" not getting called

$
0
0
Hi there,

I have a question that I need help with. I'd like to first know if first I have the correct approach and secondly if I do, what am I doing wrong? In my game, at the start the user first connects to a database to collect his account information. Once that happens, I do a few things:

PhotonNetwork.autoJoinLobby = false;
PhotonNetwork.automaticallySyncScene = true;
PhotonNetwork.offlineMode = true;
PhotonNetwork.CreateRoom("MainMenu");

While the user is in the Main Menu, he doesn't need to connect to Photon but I do need some of the Photon functionality like the use of RPCs. From the Main Menu, the user can click on "Find Match" where he gets paired up with a single opponent. Players have a personal rating and when they search for a match, they do 8 searches in a row looking for an opponent with the closest rating to theirs. So if they're at 1500 rating, they'll look for someone between 1450 and 1550, if nobody is available then 1400 and 1600 and so on for a total of 8 iterations. If nothing is found, they create their own room and place their own rating in the room options so other people looking for matches can get paired with them.

So when the player presses the "Find Match" button, I do the following:
PhotonNetwork.ConnectUsingSettings(); // with the game version inside ()
I immediately get a notification of "ConnectUsingSettings() disabled the offline mode. No longer offline."
I also get "Best region found in PlayerPrefs. Connecting to: eu"
And "OnConnectedToPhoton" and "OnConnectedToMaster" get called.
The "OnConnectedToMaster" callback checks if we're looking for a match and if we are, it does the custom search for an opponent described above and if it can't find anyone it creates a room.

So far, so good, everything seems to work perfectly. Now I also have a "Cancel Search" button. When pressed I do the following:

PhotonNetwork.Disconnect();
PhotonNetwork.offlineMode = true;
PhotonNetwork.LeaveRoom();
PhotonNetwork.CreateRoom("MainMenu");

If I press the "Cancel Search" button and then I press the "Find Match" button again, I only get as far as "Best region found in PlayerPrefs. Connecting to: eu". "OnConnectedToPhoton" and "OnConnectedToMaster" no longer get called. What am I doing wrong and is this a proper way of doing things?

Thank you!

Trying to set the camera and children/scripts on the camera to isMine but doesn't work. Please help!

$
0
0
I've recently added a new look around script(from the standard assets).
Now instead of the camerascript being on my player (and being started in ThirdPersonNetwork script) (which is on my player) I have the freelookcamerascript and the protectcamerafromwall script on my camera script.

From the quick tutorial on PUN Basics tutorial I noticed I could be doing the third option (they chose option 2) as demonstrated here:


Script is below with a link from codepad. At the moment I'm just enabling and disabling the camera but as soon as someone joins the camera gets disabled for them as they are not the owner.

Please help, I've been breaking my head over this for hours!

Camera hierarchy


Camera scripts:


Script FreeLook:
https://codepad.co/snippet/EPjrfg1v

So I suppose my main question would be: How do I achieve this?
The follow up would be: How can I, in the future, decide which object should belong to me? (also, how does the photon view work, which transform should I put in there? Or none?).

PUN onPhotonSerializeView lag between bigger and bigger

$
0
0
I'm using Photon standalone server and Unity to make multi-player game in Unity. However, I get trouble with photon onPhotonSerializeView, my code is:



I want to get lag of synchronization. At the beginning, lag can be small, such as 100ms, but when the player keeps moving on one device, the lag will be bigger and bigger, and the dummy player on another device move like delay. After some time, the lag can be 20s or more.
My Unity Photon inspector is as follows:



File *playerMovement.cs* contains `OnPhotonSerializeView` code.
Can anyone help me?

Photon room questions

$
0
0
Hello guys,

is there a way to create properties of a room which are visible to all players in a lobby? According to other posts the Room options are only visible to players of the current room, can I somehow send specific entries accross the network to all players in the lobby? My game has the option to choose different rulesets which should be displayed to the player before joining, those can be changed while being in the room. I thought about using the room name to add the rules and fish it out from there, but then I would need to change the room name while in the room when the rules change.

PhotonChat

$
0
0
with PhotonChat I can have an option where the player clicks on a person's name to display a menu to call her for a match?
I need ideas, I've seen many games have this..

Transfership set to scene but gameobject still gets destroyed when master client leaves

$
0
0
Hi, I'm trying to manually instantiate a scene object and sync it's transform using Photon Transform View, everything works great and it's syncing , but the only problem I'm having is even after setting the gameobjects ownership to 0 (scene) when I disconnect the master client who instantiated it , it gets destroyed. Here's my code:

IEnumerator spawm(float starttime)
{
...
...
...
PhotonView photonView = this.GetComponent ();
int id = PhotonNetwork.AllocateViewID ();
if (PhotonNetwork.isMasterClient)
photonView.RPC ("spawnNetwork", PhotonTargets.All, a, directionPos, pos, euler, id);
...
...
...
}

[PunRPC]
void spawnNetwork(int a, int directionPos, Vector2 pos, Vector3 euler, int id){

_tr = Instantiate (_pre [a]).transform; //instantiate the fish
_tr.position = pos;
_tr.eulerAngles = euler;
if (PhotonNetwork.isMasterClient) {
_tr.GetComponent ().enabled = true;
_tr.GetComponent ().enabled = true;
}
_tr.GetComponent ().viewID = id;
_tr.GetComponent ().TransferOwnership (0);

}
I understand I can use Photon.InstantiateSceneObject, but the game I'm working on is a single player game template that I bought and that I'm trying to convert to multiplayer and moving so much enemy prefabs to the Resources folder ends up breaking scripts. As a noob it took me two full days to figure out how to sync them and I've learned alot and how powerful Photon can be if used the right way and I'm loving it :).. so just wanted to see if anyone had any advice on how to keep those instantiated gameobjects in the game even when they're owned by the scene. Thanks!

How to get scene load progress when using photonnetwork.loadlevel

$
0
0
Hi,

I use photonnetwork.loadlevel to load my scenes and I have it set up so that when the master client switches the other players in the room automatically switch as well.

Usually in unity to do a progress bar for loading a scene you would use async load and then check operation progress to see how far you had got in order to update your loading progress.

With photonetwork.loadlevel I'm not aware of how I would get the scene progress as there doesn't appear to be any way of checking load progress?
I'm aware photon doesn't have an async load so how do I go about getting the scene load progress for the master and the various joined hosts so they can be presented with some time line type information on how long they will need to wait for the scene to load?

I can use a room to be a lobby ?

$
0
0
my idea is that doing this I could keep everyone connected and with the chat running via RPC
Has anyone had this experience?

can't understand sendRateOnSerialize

$
0
0
Hi there,

I just did some profiling on the OnPhotonSerializeView method to see if it was called the correct number of times, and the results seem weird to me:

let's say my settings are:
SendRate = 30
SendRateOnSerialize = 20

the photonView is set to Unreliable. So from what i understand, it will always send updates even if the values do not change, this should make the calls to OnPhotonSerializeView consistent.

So, every time OnPhotonSerializeView is called on the character, i get the time since the last time it was called and put that time in an array containing a 100 or so values (tried with 1000 too just to be sure). i displayed the medium of the values in said array, expecting to see something around 50ms (20 frames per second makes for 50ms between frames yes?) with my settings, i get around 65... with other settings it's the same i always get more time than i expect between calls to OnPhotonSerializeView(), on the receiver and on the sender side too...

Why is that? is there something i don't know or forgot to take into account?

Thank you for your answers =D

PhotonChat

$
0
0
I need a system to call chat people for a match, in other words send a popup message to a person by clicking on their name in the chat, and I do not know how to do this.

i need idea =/

Using photon (how to synchronize) with other types

$
0
0
Using supported types I've already learned.
And unsupported types you Serialize / Deserialize.
But how do you set these values in my components?
In my current project, there is dynamic ground.
The sprite on the ground changes.
How do I send via RPC with the command to change the sprite?
Or the same thing by OnPhotonSerializeView?
How to sync a collider?
Excuse me, I'm a beginner ... But I can do some things already
_____________________________________________________________________________
I tried the following way:

private Sprite s;

private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting) //Local player - send data
{
stream.SendNext(ObjectToByteArray(GetComponent().sprite));
}
else //Remote player - receive data
{
s = (Sprite) ByteArrayToObject((byte[])stream.ReceiveNext());
}
}
------
after
...
if (photonView.isMine)
{
DestroyGround();
// Destroys the ground by applying the contact areas of the circle collider to transparent pixels and applies the
//change in texture.
}else{
GetComponent().sprite = s;
}

...
____________________________________________________________________________________________
Or with RPC

when to destroy the texture and, apply, get the byte texture []...
And call RPC with a byte parameter []...
... photonView.RPC("change", PhotonTargets.All, spriteData);

There in the RPC

private void change(byte[] b ){
GetComponent().sprite = (Sprite) ByteArrayToObject( b );
}

__________________________________________________
Excuse me if the code is messy.
I do not know what else to do, I'm lost in that part.
I was able to synchronize the position and rotation.
With only this, I am already happy > _ <

WebRPC Message Size Limits

$
0
0
Hey guys

I'd like to ask one of the Photon developers if there is a limit on the size of a WebRPC message. At this point, it's still hypothetical, but we're looking at some way to upload some userdata when they achieved something, i.e. a recording of their path after they finish. I'd prefer to use the mechanisms we already have in place right now (WebRPCs) to send this data over so that we can have a more solid check of validity of the actual user uploading it (the AuthCookie really helps).

So my actual question is; is there currently a hard-limit on the size of a WebRPC message? If so, what is this limit? The file sizes we're looking right now at are on average ~200KB-500KB with a maximum of ~4MB (if they manage to race for roughly 4 hours...).

Thanks in advance!

WebGL/WSS: Error: Abnormal disconnection after having isMessageQueueRunning = false for ~16 seconds

$
0
0
Try it yourself: http://trail-demos.s3.amazonaws.com/photonbug/index.html

Using PUN v1.90 and Unity 2017.4. There is one simple Script running:
    public IEnumerator PrintState() {
        ClientState lastState = ClientState.Uninitialized;
        while (true) {
            var state = PhotonNetwork.connectionStateDetailed;
            if (state != lastState) {
                Debug.Log("detailed state change: " + state);
            }
            lastState = state;
            yield return null;
        }
    }

    public IEnumerator PrintSimpleState() {
        ConnectionState lastState = ConnectionState.Disconnected;
        while (true) {
            var state = PhotonNetwork.connectionState;
            if (state != lastState) {
                Debug.Log("simple state change: " + state);
            }
            lastState = state;
            yield return null;
        }
    }

    public void Awake() {
        StartCoroutine(PrintState());
        StartCoroutine(PrintSimpleState());
    }

    public void Start () {
        PhotonNetwork.ConnectUsingSettings(null);
    }

    public void OnJoinedLobby() {
        PhotonNetwork.CreateRoom("a room");
    }

    public void OnJoinedRoom() {
        Debug.Log("setting PhotonNetwork.isMessageQueueRunning = false");
        PhotonNetwork.isMessageQueueRunning = false;
    }

Webhooks / load gamestate

$
0
0
Hello,

I'm at a point where I want to load a gamestate for a rejoining player who previously got disconnected. If I use a web server and webhooks to restore the gamestate, how much of the work is done by the photon sdk? Do I have to download the Photon Server sdk and run it on a dedicated server? I wanted to test out the Memory Game Demo but I can't seem to find it, is it included in the unity store asset? If yes, I must be blind.

On another thought, with how much data can I fill the custom room properties before the performance drops noticeable? I would store the data from objects that got changed in the room properties and load it from there after re-joining.
Photon seems really powerful but the documentation is not really insightful at first glance, at least for beginners.
Viewing all 8947 articles
Browse latest View live


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