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

foreach Player error

$
0
0
Hi guys, I have a problem with a foreach bucle I made, this is the code:
  foreach (Photon.Realtime.Player Player in PhotonNetwork.PlayerList)
            {
                int GameCount = (int)PhotonNetwork.LocalPlayer.CustomProperties["GameCount"];
                UnorderedList.Add(GameCount);
                print("Player");
            }
So, in theory, as the documentation says, this PhotonNetwork.PlayerList property has inside, all the players In the room. So, by following this logic, this foreach should repeat 2 times if there are 2 players, if there are only 4 players, the loop should repeat 4 times, right? But this is not happening, it repeats A LOT of times, as you can see I have a print line, this message printed 70 times in the console, meaning that the loop repeated 70 times until I stopped the debug. This is giving me wrong values, does someone know why is this happening and how can I fix it?

Increasing MAX_VIEW_IDS

$
0
0
I'm making an RTS game. Player's can chop down trees & destroy rocks that spawn on the map in order to gather resources. The problem is that there are probably around ~4,000 of these objects and MAX_VIEW_IDS is 1000. The solution I think is to increase the MAX_VIEW_IDS. Is there any problem to doing this? The only calls each resource would make it when a worker hits it, it'll tell everyone how much it has left and when its empty the host will destroy it. So with that in mind, is there any downside to increasing MAX_VIEW_IDS ? And if so, do you have an alternative solution? Sincerely, Blake Gillman

PUN and Oculus Avatars crash

$
0
0
Hello, i have a problem with my app that uses Oculus Avatars with PUN. Problem is that i have a Oculus GO headset that crashes after a few runnigs of the app. https://pastebin.com/0m6RHW1b - avatar serialization code https://i.imgur.com/rJkt45r.png https://i.imgur.com/Y0QlHyD.png logs of the crash. Thank you in advance.

ConnectMenu.cs(291,19): error CS1501: No overload for method `CreateRoom' takes `6' arguments

$
0
0
im getting an error saying Assets/fpis/FPS Kit 2.0 C#/_CustomAssets/Scripts/Network/ConnectMenu.cs(291,19): error CS1501: No overload for method `CreateRoom' takes `6' arguments does anybody know how to fix it pls im struggling with this error this is where im getting the error PhotonNetwork.CreateRoom(newRoomName, true, true, maxPlayers, setMapName, exposedProps);

How to get all players custom properties

$
0
0
I have a Unity 3D Project and I'm using Photon's PUN2 to make and online mode. I need to get the Player Custom Properties for all the players in the actual room. Does someone know how I can do this?

Inventory Singleton Issue

$
0
0
Hello, I am new using Photon PUN 2 and i am facing to an issue. i am trying to implemente Inventory system My inventoryManager is singleton evething work well but when i drop an item on the ground if i pickup it with an other player this item is always put back in the inventory of the player who throw this item. i transfer ownership of the Object to the player who collier with but same thing, so maybe it's because my inventory is singleton but i don't understand how the gameobject can be placed back in the creator inventory because this inventory is not networked so there is 1 inventory Singleton on each client and each client have à knowledge about inventory singleton of other player If someone can help me pls :)

Teleport-like abilities while using Photon Transform View

$
0
0
Hello! I'm new with Photon and am wondering what the best-practice is for this type of a functionality. So basically if I have a player using a teleport skill, on the remote users I want them to see the player teleport, not lerp into position using the standard Photon Transform View. I can think of a couple of ways of doing this: 1. Writing my own transform sync code entirely, using either RPCs or OnPhotonSerializeView and choosing how to handle the position coordinates based on the distance to the previous position 2. Add a reference of Photon Transform View to the script that controls the player position. If previous position has enough distance to next position, toggle transform sync off, do the teleport, sync the new position manually and re- enable Photon Transform View when the updated position has been synced. 1. seems easier, but am I missing some important and useful functionality by choosing not to use Photon Transform View... Is either method considered "supreme", is there some other really good way that I'm not thinking of or does the best practice always vary case by case?

Set CustomProperties by Plugin

$
0
0
Hi, There is a way to me set a Room Custom Propertie by plugin? For example. If I had a custom propertie to set total players destroyed on room, but the count of destroyed is made by plugin, so I want that the Plugin could set this custom propertie. Is possible?

Call a custom Class from PhotonNetwork.cs

$
0
0
Hey, In my game I need to make a small change in PhotonNetwork.cs. From withing this PhotonNetwork Class I need to call a Class of my own. But It seems I can't access it. Probably because it's in a different assembly. I tried to put my Class in a namespace and included it in the PhotonNetwork.cs Class. But it doesn't recognises it. Does somebody had a similar issue and possible solution? Regards,

npc ai

$
0
0
Hello, I had a problem when developing a small mmorpg. in question it is the npc, they have an ai that is responsible for chasing the player when it approaches the npc range. it works excellent, when I test it with a single player the npc follows me, but the problem comes when a second player is connected, when he approaches the npc he pursues him but performs 3 totally gross jumps and then returns to his rest position, so it only happens to work correctly only with the master client, in question, does anyone know why the npc only chases the master client but ignores the player2? and excuse me if my English is something bad, I do not get used to it yet

Internet connection issues

$
0
0
Hi , We have integrated PUN for one of our game. We are facing some issues related to internet connection. Player 1 and Player2 connected in one of the PvP game. Some time later Player 1 lost internet connection for 3 seconds and came back. Player2 got an event immediately after player1 lost connection, but player1 didn't received any event related to failure connection immediately (Received after 60 sec), and for player1 still showing connected TRUE. Other issues is even after player1 got internet connection , message passing is not happening between two players.

Photon server and PUN 2 samples

$
0
0
tell a newbie please. Installed the last server. I installed the last PUN2 in the new unit project. Set the correct connection address in the settings 127.0.0.1:5056. But when I try to connect, I get an error Got a unexpected Disconnect in LoadBalancingClient State: Disconnected. Server: MasterServer Trace: at Photon.Realtime.LoadBalancingClient.OnStatusChanged(StatusCode statusCode) in C:\!Unity\TestPhoton\Assets\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:line 2302 at ExitGames.Client.Photon.PeerBase+<>c__DisplayClass100_0.b__0() in C:\Dev\photon-sdk-dotnet\PhotonDotnet\PeerBase.cs:line 895 at ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands() in C:\Dev\photon-sdk-dotnet\PhotonDotnet\EnetPeer.cs:line 429 at ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands() in C:\Dev\photon-sdk-dotnet\PhotonDotnet\PhotonPeer.cs:line 1422 at Photon.Pun.PhotonHandler.FixedUpdate() in C:\!Unity\TestPhoton\Assets\Photon\PhotonUnityNetworking\Code\PhotonHandler.cs:line 126 UnityEngine.Debug:LogWarning(Object) Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:1814) Photon.Realtime.LoadBalancingClient:OnStatusChanged(StatusCode) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2304) ExitGames.Client.Photon.<>c__DisplayClass100_0:b__0() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:895) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:429) ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1422) Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:126)

Changes in PUN2 ReconnectAndRejoin()

$
0
0
I am trying to migrate a small project built with PUN Classic onto PUN2 and having some trouble figuring out if there are changes in ReconnectAndRejoin(), and if so, how to work with the new version. Context of code: I simulate a loss of internet connectivity by switching off WiFi on the computer and test re-connection by switching it on again after a few seconds. In the older PUN classic, I repeatedly called ReconnectAndRejoin() in the OnDisconnectedFromPhoton() callback till the internet connection is restored. Once connectivity is restored, the last ReconnectAndRejoin() would put the user back into the original room. However, a similar approach seems to fail with PUN2. I try to repeatedly call ReconnectAndRejoin() in the OnDisconnected(Disconnect cause) callback but see that ReconnectAndRejoin() fails on the second/third iteration as the state of NetworkingClient.LoadBalancingPeer.PeerState has changed from 'Disconnected' to 'Connecting'. After 2 attempts to ReconnectAndRejoin(), we no longer receive any calls to OnDisconnected(). Any help/guidance on changes to behaviour of ReconnectAndRejoin() are appreciated.

Why is photon instantiating double the players? (Unity3D)

$
0
0
Hi Everyone, I have a really quick question. The script is working except it instantiates the player twice and I cannot figure out why. Here is the outline of the script: 1) Waits until enough players join 2) Once enough players have joined a countdown from 5 seconds starts 3) All players are joined into a new multiplayer scene I can't figure out why double of every player are being instantiated. Thanks! Here is my script:
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using System.IO;

public class PhotonRoom : MonoBehaviourPunCallbacks, IInRoomCallbacks {

    // Player settings
    private PhotonView PV;
    public Player [] players;
    public int playersInRoom;

    // Game settings
    private bool isGameLoaded = false;
    private bool doneLoading = false;
    private bool readyToStart = false;
    private int currentScene = 0;
    private int multiplayerScene = 1;

    // Count down
    private float countFrom = 6;

    void Awake () {
        DontDestroyOnLoad (this.gameObject);
    }

	private void Start () {
        PV = GetComponent ();
	}

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

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

	private void Update () {
        if (!isGameLoaded) {
            if (readyToStart) {
                Debug.Log ("Hit1");
                countFrom -= Time.deltaTime;
                Debug.Log ("Time left: " + countFrom);
            }
        }
        if (countFrom <= 0) {
            if (doneLoading == false) {
                StartGame ();
                doneLoading = true;
            }
        }
	}
   
	public override void OnJoinedRoom () {
		base.OnJoinedRoom ();
        players = PhotonNetwork.PlayerList;
        playersInRoom = players.Length;
        if (playersInRoom % 2 == 0) {
            readyToStart = true;
        }
        if (playersInRoom == PhotonNetwork.CurrentRoom.MaxPlayers) {
            if (!PhotonNetwork.IsMasterClient)
                return;
            PhotonNetwork.CurrentRoom.IsOpen = false;
        }
	}

	public override void OnPlayerEnteredRoom (Player newPlayer) {
		base.OnPlayerEnteredRoom (newPlayer);
        players = PhotonNetwork.PlayerList;
        playersInRoom++;
        if (playersInRoom % 2 == 0) {
            readyToStart = true;
        }
        if (playersInRoom >= PhotonNetwork.CurrentRoom.MaxPlayers) {
            if (!PhotonNetwork.IsMasterClient)
                return;
            PhotonNetwork.CurrentRoom.IsOpen = false;
        }
	}

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

    void OnSceneFinishedLoading (Scene scene, LoadSceneMode mode) {
        Debug.Log ("This was called");
        currentScene = scene.buildIndex;
        if (currentScene == multiplayerScene) {
            isGameLoaded = true;
            PV.RPC ("RPC_LoadedGameScene", RpcTarget.MasterClient);
        }
    }

    [PunRPC]
    private void RPC_LoadedGameScene () {
        Debug.Log ("Players in Room: " + playersInRoom);
        Debug.Log ("PlayerList.Length: " + PhotonNetwork.PlayerList.Length);
        if (playersInRoom == PhotonNetwork.PlayerList.Length) {
            PV.RPC ("RPC_CreatePlayer", RpcTarget.All);
        }
    }

    [PunRPC]
    private void RPC_CreatePlayer () {
        PhotonNetwork.Instantiate (Path.Combine ("PhotonPrefabs", "PhotonNetworkPlayer"), transform.position, Quaternion.identity, 0);
    }
}

Photon View - incorrect name

$
0
0
Hello. The "Photon View" component can't be added through the inspector because the name is spelled wrong somewhere. https://imgur.com/a/QAGsJuK But it can be added correctly through the top left component drop down.

Namespace 'ExitGames' could not be found.

$
0
0
This has been asked before, but the accepted answer was that the user started all over again and it just worked, which obviously isn't much help. My project runs fine in Unity, but I can't attach visual studio because this doesn't compile because of a missing reference to 'ExitGames', which I assume would be in the dll 'Photon3Unity3D.dll'? I have downloaded the latest Photon Realtime and in VS have clicked 'Include in Project' everything in PhotonLibs, PhotonRealtime and PhotonUnityNetworking. Including these allowed it to recognise 'Photon.Pun' and 'Photon.Realtime', but not 'ExitGames'. I couldn't see a way to 'add references' specifically to this, or to use Nuget to do it. This doesn't stop me developing on the project, but losing the ability to debug code in visual studio is a problem. I'm using Unity 2017.3.1, and Visual Studio Community 2015 (14.0). I can upgrade if required. Thanks in advance. Photon is awesome.

Best way to reconnect to Master Server after timeout?

$
0
0
Hi I would like to know what the best way is to reconnect to the Master Server when the client times out. Currently I start a coroutine at .OnDisconnected() that calls .Reconnect() every 2 seconds. This seems to work because when I turn off my internet connection for like 10 seconds the coroutine gets called. When the internet connection is back the .Reconnect() successfully connects me to the Master Server again. So this solution works, but my question is if this is the suggested solution? Do you guys also use coroutines to reconnect? Thanks! Using: Photon PUN 2.4

PUN 2 - Get Custom Properties Of Players

$
0
0
Hi everyone, I tried looking for documentation to find my solution to this but have had no luck. I am trying to access each player's custom properties to check their team. this is what I want: PhotonNetwork.Player.GetCustomProperties["Team"].ToString(); How can I do this in PUN2? Thank you!

[Question] How to get photon scripts to recognize my class.

$
0
0
I would like to add something like (&& LevelManager.IsTesting) at the if (netView != listedView) place. But LevelManager doesnt seems to be recognize. Any help would be appreciated.
bool isViewListed = photonViewList.TryGetValue(netView.ViewID, out listedView);
            if (isViewListed)
            {
                // if some other view is in the list already, we got a problem. it might be undestructible. print out error
                if (netView != listedView)
                {
                    Debug.LogError(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.ViewID, netView, listedView));
                }
                else
                {
                    return;
                }

                RemoveInstantiatedGO(listedView.gameObject, true);
            }

Illegal view ID: 0 Error

$
0
0
Hi, I've recently started working with the PUN package in Unity. I am sort of new to developing, and I have been having trouble getting networking to work (most problems I've resolved through google, of course).

There is this one issue that I have not been able to find an answer to, however. I keep getting this error: "Illegal view ID:0 method: SwordRPC GO:game_controller".
Basically, my setup is a button that calls the SwordRPC method of a script component in the game_controller object. Game_controller is instantiated through PhotonNetwork.Instantiate and has a Photon View.

Whenever I debug it by checking the photon view ID every frame (on Update), it gives me a completely valid ID. But when I debug it by checking the ID in the method, it gives me 0. Strange!
Viewing all 8947 articles
Browse latest View live


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