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

Error says I don't have a PunRPC function that takes in int parameter, but I do

$
0
0
This one's quite bizarre but I can't seem to figure it out. It looks pretty straightforward, here's my RPC function and the call -
(https://imgur.com/a/QDzdH0i)
public void OffensiveOccuppied(EPlayerController controller)
    {
        int tID = controller.GetComponent<PhotonView>().ViewID;
        Debug.Log("View Id = " + tID);

        PhotonView tView = GetComponentInParent<PhotonView>();

        tView.RPC("RPC_OffensiveOccupied", RpcTarget.All, tID);
    }

    [PunRPC]
    void RPC_OffensiveOccupied(int controller)
    {
        Debug.Log(name + " is now being controlled by " + controller);
        controllingPlayer = controller;
        isOccupied = true;
        PhotonView.Find(controller).transform.position = playerAnchor.transform.position;
        Camera cam = PhotonView.Find(controller).GetComponentInChildren<Camera>();
        cam.transform.SetParent(this.transform);
        cam.transform.localPosition = cameraAnchor.transform.localPosition;
        cam.transform.localRotation = cameraAnchor.transform.localRotation;
    }

So as can be seen here, I do have a PunRPC-marked function that takes an int parameter, but I still get this error message -

PhotonView with ID 1003 has no (non-static) method "RPC_OffensiveOccupied" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: Int32
UnityEngine.Debug:LogError(Object)

'PhotonNetwork' does not contain a definition for 'Playerlist'

$
0
0
The script is using the namespaces; Photon.PUN and Photon.Realtime. PhotonNetwork can't recognize 'Playerlist' I wonder what can cause this issue.
pun.jpg

Free roam and photon pun

$
0
0
Hello,
I making game about cars heavily based on multiplayer in unity 3d. Player will start in a lobby in which he can buy and customize his car, after that we will go to free roam where he would drive around a map. During drivnig around a map he can also start a race in special places with other players. Similar system was in need for speed world. Here is my question is it possible to do it in photon?

Regular disconnects

$
0
0
I began to notice regular disconnects, even when connected to a local server. When connected to a remote server disconnects happen even more often. I can't remember it happening that often before. PunVersion = "2.15"

Do I need to update the room's expected player list if a single player drops out before joining?

$
0
0
If I join a room and set the expected player id's, the room will set aside a slot for each user. If for some reason one of those users will not join how can I update the expected users property so that there isn't a single unused spot in the room?

I see there is an option to clear all expected players, but that seems like a hassle to manage given the very clear warning that this could have a race condition with joining players.

I've read this forum post and don't think it covers the full subject: https://forum.photonengine.com/discussion/8259/callback-for-updates-to-rooms-expectedusers

I'm thinking the solution right now is to:
1) Close the room.
2) Wait X seconds.
3) Clear the expected users list.
4) Set the expected users list with all the old values minus the one we know isn't there.
5) Reopen the room.

I'm stuck at step 4 right now.

JoinRandomRoom Failed

$
0
0
I know, this problem is already been asked by many people, but it didn't work well for me. I got this error when I'm making a room for a player. Here's my code


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


public class LaunchManager : MonoBehaviourPunCallbacks
{
public GameObject EnterGamePanel;
public GameObject ConnectionStatusPanel;
public GameObject LobbyPanel;


#region Unity Methods

// Start is called before the first frame update
void Start()
{
EnterGamePanel.SetActive(true);
ConnectionStatusPanel.SetActive(false);
LobbyPanel.SetActive(false);
}

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

}

#endregion


#region Public Methods

public void ConnectToPhotonServer()
{
if (!PhotonNetwork.IsConnected)
{
PhotonNetwork.ConnectUsingSettings();
ConnectionStatusPanel.SetActive(true);
EnterGamePanel.SetActive(false);
}

}

public void JoinRandomRoom()
{
PhotonNetwork.JoinRandomRoom();
}

#endregion


#region Photon Callbacks

public override void OnConnectedToMaster()
{
Debug.Log(PhotonNetwork.NickName+ " Connected to Photon Server!");
LobbyPanel.SetActive(true);
ConnectionStatusPanel.SetActive(false);
}

public override void OnConnected()
{
Debug.Log("Connected to Internet!");
}

public override void OnJoinRandomFailed(short returnCode, string message)
{
base.OnJoinRandomFailed(returnCode, message);
Debug.Log(message);
CreateAndJoinRoom();
}

public override void OnJoinedLobby()
{
Debug.Log(PhotonNetwork.NickName + " joined to " + PhotonNetwork.CurrentRoom.Name);
}

#endregion


#region Private Methods

void CreateAndJoinRoom()
{
string randomRoomName = "Room";
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsOpen = true;
roomOptions.IsVisible = true;
roomOptions.MaxPlayers = 20;

PhotonNetwork.CreateRoom(randomRoomName, roomOptions);

}

#endregion
}

Need help with VR Multiplayer

$
0
0
I took a course on Unity muliplayer and created a Battle Royal game that works great. Using that as a base I constructed a simple scene that after connecting to a server, a player can create a game and start it in a lobby. If I start the game without any other players, the scene loads and the player is instantiated and can walk around and get no errors. My player has a simple capsule body and 2 low poly hands. When I start the game with another player (my other Oculus), in either headset, I can look around, see the other player where they spawned, but our players are frozen.

I am sooooooo close to creating a multiplayer VR game and just need a little help understanding what I did wrong and how everything should be structured. There are absolutely NO tutorials on creating a multiplayer VR game with PUN. It would surely help a lot of people. Thanks.

The error is:
NullReferenceException: Object reference not set to an instance of an object
GameManager.SpawnPlayer () (at Assets/Scripts/GameManager.cs:51)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <567df3e0919241ba98db88bec4c6696f>:0)
Photon.Pun.PhotonNetwork.ExecuteRpc (ExitGames.Client.Photon.Hashtable rpcData, Photon.Realtime.Player sender) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:473)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2063)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2826)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:656)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:549)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1598)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

The offending code is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.Linq;

public class GameManager : MonoBehaviourPun
{
    public float postGameTime;

    [Header("Players")]
    public string playerPrefabLocation;
    public PlayerController[] players;
    public Transform[] spawnPoints;
    public int alivePlayers;

    private int playersInGame;

    // instance
    public static GameManager instance;

    void Awake()
    {
        instance = this;
    }

    void Start()
    {
        players = new PlayerController[PhotonNetwork.PlayerList.Length];
        alivePlayers = players.Length;

        photonView.RPC("ImInGame", RpcTarget.AllBuffered);
    }

    [PunRPC]
    void ImInGame()
    {
        playersInGame++;

        if (PhotonNetwork.IsMasterClient && playersInGame == PhotonNetwork.PlayerList.Length)
            photonView.RPC("SpawnPlayer", RpcTarget.All);
    }

    [PunRPC]
    void SpawnPlayer()
    {
        GameObject playerObj = PhotonNetwork.Instantiate(playerPrefabLocation, spawnPoints[Random.Range(0, spawnPoints.Length)].position, Quaternion.identity);

        // initialize the player for all other players
        playerObj.GetComponent<OVRPlayerController>().photonView.RPC("Initialize", RpcTarget.All, PhotonNetwork.LocalPlayer);
    }

    public PlayerController GetPlayer(int playerId)
    {
        return players.First(x => x != null && x.id == playerId);
    }

    public PlayerController GetPlayer(GameObject playerObject)
    {
        return players.First(x => x != null && x.gameObject == playerObject);
    }

    public void CheckWinCondition()
    {
        if (alivePlayers == 1)
            photonView.RPC("WinGame", RpcTarget.All, players.First(x => !x.dead).id);
    }

    [PunRPC]
    void WinGame(int winningPlayer)
    {
        // set the UI win text
        GameUI.instance.SetWinText(players.First(x => x.id == winningPlayer).photonPlayer.NickName);

        Invoke("GoBackToMenu", postGameTime);
    }

    void GoBackToMenu()
    {
        NetworkManager.instance.ChangeScene("Menu");
    }
}

Problem when hierarchy of instantiated objects

$
0
0
Hey newbie in photon here, i am making a phone game where i connect two players through the same wifi network, the problem is that each one of the players needs a reference to the other player but as they don't instantiate at the same time they don't get that reference in the hierarchy. I've tried setting those references in place when instantiating the second player with a punRPC function but doesn't work.

PD: It's kind of difficult to explain as English is not my main language, so feel free to ask more questions if you don't understand.

Questions regarding PUN implementation approach

$
0
0
Hi, I'm trying to implement multiplayer in my Unity project using Photon and I need some guidance. I connect to the Photon server using the defined settings and join a lobby once connected.
PhotonNetwork.ConnectUsingSettings ();
public override void OnConnectedToMaster () {
    PhotonNetwork.JoinLobby ();
}
Then, the user is given a choice to either create a public room or a private room. Before creating a room, the code checks if there is any suitable room the user can join. If not, a new room is created.
//Public room creation
RoomOptions options = new RoomOptions { MaxPlayers = 2, IsVisible = true, PlayerTtl = -1 };
PhotonNetwork.CreateRoom (*SomeRoomName*, options, null);

//Private room creation
RoomOptions options = new RoomOptions { MaxPlayers = 2, IsVisible = false, PlayerTtl = -1 };
PhotonNetwork.JoinOrCreateRoom (*SomeRoomName*, options, null);
Once all players join the room, the game starts. If a player disconnects midway, he can rejoin if the room is still active. Once the user reconnects, the other player sends him the game state using a RPC. Is there any better approach to achieve this? I also have a few other questions: 1. Sometimes the cached room list returns a count of 0 even when a room is created. Why does this happen? 2. Is there any way I could save data on the Photon servers? Thanks in advance!

UDP package is full

$
0
0
I have an issue with my game. When I make an IO game. When I InstantiateSceneObject 3 AI players(in-game player who controlled by AI) and there is A(Master client) and B(another client) in the same room. After a while, B will disconnect but there is no player B's left game logs in A's console(but I can't see the B's move from A's screen). But when I set AI players from 3 to 1. It doesn't happen. Is that because I send too much data?

Also, sometimes, I will receive log "UDP package is full. Commands in Package....." in the console after entering the room.

clients and editor cannot see eachother, unless assets are duplicated into a blank new project?

$
0
0
USING LATEST PUN 2 AND UNITY 2018.3.11f1
So I've been working on this project for a little over a month now, but I keep getting dissuaded since- seemingly at random- my project's builds and editor will no longer see each other when I test the game out. I'm still using the Asteroids Demo Lobby for the initial connection and lobbymaking, so I know all of that is fine. However, eventually any room I create in my editor cannot be seen by my build and vice versa (when both run on the same computer). If I open two windows of the build on the same computer, then those two can communicate and connect to eachother perfectly, but any other computer I run the build on, along with the editor, cannot.
I've tried reimporting Photon, trying a different appID, app version, build version, and reset all project settings, and none of those fix the problem. Nothing should be putting the game in offline mode either.
The only thing that does seem to actually fix it, is either copying and pasting the whole assets folder of the project into a new blank project, or exporting the whole project into an assetpackage and importing it into a new blank project.

Has anyone experienced this?
I guess logically I should update Unity to the latest version, but this version has been working fine for me for a while, and I'm almost out of hard-drive space, so I was wondering if this is a known issue

Pong Game Lag Problem

$
0
0
Hello guys,
I'm working on pong game and I have some trouble.
I am synching paddle position from script(I found it on internet and best for what I tried for sync). Script attached below:
public Vector3 realPosition = Vector3.zero;
     public Vector3 positionAtLastPacket = Vector3.zero;
     public double currentTime = 0.0;
     public double currentPacketTime = 0.0;
     public double lastPacketTime = 0.0;
     public double timeToReachGoal = 0.0;
     
     void Update ()
     {
         if (!photonView.isMine)
         {
             timeToReachGoal = currentPacketTime - lastPacketTime;
             currentTime += Time.deltaTime;
             transform.position = Vector3.Lerp(positionAtLastPacket, realPosition, (float)(currentTime / timeToReachGoal));
         }
     }
 
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if (stream.isWriting)
         {
             stream.SendNext((Vector3)transform.position);
         }
         else
         {
             currentTime = 0.0;
             positionAtLastPacket = transform.position;
             realPosition = (Vector3)stream.ReceiveNext();
             lastPacketTime = currentPacketTime;
             currentPacketTime = info.timestamp;
         }
     }

Ball has classic photon transform view with lerp option and also photon rigidbody view. Ball istantiating from script as scene object and default controlling by master client. I just update ball rb.velocity on start and when collision occur from who is master client. With this approach guest player sees game as reflection. When guest player is one corner of game area and trying to reach other corner for interact with ball. Guest is reaching that point on the time in own game but position sync is not one to one. So ball is gone outside game area on master client view when guest interact with ball. Then ball lagging on guest until come game area again.
What is the best approach for this situation? Do I need request ball ownership for each client before interact with the ball? If case is this which side must detect collision? Should the ball detect the collision again or the paddle?

Thanks in advance and sorry for my English.

Cant get Bools to Sync OnPhotonSerializeView

$
0
0
typically i have the MasterClient Photon.Instantiate a gameObject and then set some bools to initialize it. IsPoisonous = true, isHealthPickup = true. But i cant for the life of me get these to sync with client players. Int works fine. the scripts are observed components. Am i missing something. Using Pun classic.

Created Unity game using PUN2 and cloud. Now want LAN server.

$
0
0
Hello,

We have been working on a project for a few months here, but discovered that we will require a LAN connection and will not be able to access the internet. So, looking at the available Photon On Premise documentation... it's still unclear on how one set up their Unity application to work with the Photon Control that sits in the task bar.

I have tried just entering the 127.0.0.1 and port into the settings where the appID used to be. I feel like I'm missing a step.

These are the two references I have
https://doc.photonengine.com/en-us/server/current/getting-started/photon-server-intro
https://doc.photonengine.com/en-us/server/current/getting-started/photon-server-in-5min#game_server_ip_config

I feel like the 'Photon server in 5 min' is a bit slim on details and could use a walk through video with an example Unity application.

Any help is appreciated.

Is it possible in PUN to get something like Android Nearby Connections?

$
0
0
I wanted something that worked without internet, and that users didn't have to type in any kind of IP Address. I could use Android Nearby Connections itself, but I also want it to be cross-platform.

Bug Question

$
0
0
How can solve this bug the missile has a scrip with

image https://ibb.co/Gn0MqTf
private void OnCollisionEnter(Collision collision)
{
Destroy(this.gameObject);
}

on it

missile destroy on the clien on this has been instanciates but in othes, not they just stay statik

image of the prefab https://ibb.co/N3S4vsK

please help me :confused:

Match making in Photon

$
0
0
Hi,
I am trying to create a room and joined a player in the room using photon 2. Here is my code.
//for Create Room
void CreateAndRoom()
{
float randomRoomNo = Random.Range(1.0f, 50.0f);
RoomOptions RoomOp = new RoomOptions();
string[] customProperty = {
playerroomtype
};
RoomOp.CustomRoomPropertiesForLobby = customProperty;
ExitGames.Client.Photon.Hashtable prop = new ExitGames.Client.Photon.Hashtable();
prop.Add(playerroomtype, "readytojoin"); // playerroomtype is 2 player room or 4 player room
RoomOp.CustomRoomProperties = prop;
RoomOp.IsVisible = true;
RoomOp.IsOpen = true;
RoomOp.MaxPlayers = (byte)Data.CurrentSelectedPlayer;
PhotonNetwork.CreateRoom(randomRoomNo.ToString(), RoomOp, TypedLobby.Default);
Debug.LogError("ROOM NAME " + randomRoomNo.ToString());
}
//for joined room and create new room. in this method i am calling in button clicke event
public void QuickMatchRoomes()
{
for (int i = 0; i < createRoom.Count; i++)
{
if (createRoom.CustomProperties.ContainsKey(playerroomtype) && createRoom.PlayerCount != Data.CurrentSelectedPlayer)
{
if (createRoom.CustomProperties[playerroomtype].ToString() == "readytojoin")
{
found = true;
PhotonNetwork.JoinRoom(createRoom.Name);
}

}
}
if (found == false)
{
CreateAndRoom();
[code]
[/code] WaitingPanel.SetActive(true);
}
}

Also, I am updating the room list. it works well for 2 player rooms and 4 player rooms. when a new player joined the 2 player rooms and 4 player rooms it 's not working.

Best way to network several player owned units at a time...

$
0
0
Hi,

In my prototype each player moves around the level with a few friendly characters following them (could be up to 10). So you move around while friendly characters authoritative to you follow you through the map, each of the four players in game also have this.
At the moment I just have each 'follower AI' individually updating their positions to the network via the stream update. I'm looking to ramp up the numbers (I wanna push 20-30 for each player). While I'm doing this, I'd like to know if it would be best to instead have a sort of "FollowerAISync" script that sends all their positions to stream instead of having a separate update for each one.... Would this reduce each player's load on the network?

Example:
Instead of having this for each guy...
 private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(followerAI.transform.position);
            stream.SendNext(followerAI.transform.rotation);
        }
        else
        {
            TargetPosition = (Vector3)stream.ReceiveNext();
            TargetRotation = (Quaternion)stream.ReceiveNext();
        }
    }

Would it be better to list these guys and update to the stream by looping through the list?
 private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            foreach (GameObject follower in Followers)
            { 
                 stream.SendNext(follower.transform.position);
                 stream.SendNext(follower.transform.rotation);
            }
        }
        else
        {
            foreach (GameObject follower in Followers)
            { 
                TargetPosition = (Vector3)stream.ReceiveNext();
                TargetRotation = (Quaternion)stream.ReceiveNext();
            }
        }
    }


Feedback would be greatly appreciated.

Photon disconnection issue

$
0
0
Hi,

Photon disconnect on after 3 seconds while press oculus home button. how to increase the diconnection timeout after onApplication pause.

PUN version 2.5 Unity version 2019.2.3f1

Thanks in Advance.

Freezing and disconnect issues

$
0
0
Hi,

We made a realtime quiz game that has different rounds using photon. The game is simple ,each player starts with a pool of seconds and has to answer questions and gets seconds as reward, some rounds even have their pool of seconds countdown every second.

The game has been released for a while but we are experiencing some freezes on several (mostly HUAWEI) devices.
When players join a lobby and the lobby gets full (3 players in total) the game counts down and then starts. Right after the countdown the master spawns al network objects needed these are:

- 3 network player objects, object used to send the state of each player, state is a enum (byte) that is send via OnPhotonSerializeView
- 3 NetworkSeconds objects, containing the time of each player, these are scene objects controlled by the master, seconds (float) are being send in OnPhotonSerializeView

I was wondering if the amount of objects we spawn at the same time could cause these freezes? The game hangs and people have to force close it. In our crash reports we do not see anything related to instantiating or anything else that happens at that time.

Users are also telling us they have frequent disconnects (ClientTimeout and ServerTimeout) during the game, but besides the state and seconds we hardly send anything, only RPCS are used to change the state of the game.

Thx in advance for the help
Viewing all 8947 articles
Browse latest View live