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

Disconnected From Photon

$
0
0
Hello There,
My Game is Currently running and when phone call received my game is disconnected from photon server.

How to resolve problem?


CustomRoomPropertiesForLobby is sending back NULL

$
0
0
I'm trying to have my main menu have a server list show the list of all available servers/rooms to join. I'm trying to give each server the custom property to have a description to summarize the server's gamemode, rules, etc. The server is indeed created and shows up in the server's list on a separate client, but i can't seem to get the description to get sent over, no matter what I do. Any ideas? Thanks.

Client 1 creates the server w/ name & desc.
xyWEUuP.png

Client 2 previews server list and doesn't see custom description.
9KRqGjw.png

The 1 error says that the custom properties is null and has nothing in it.
YF41kAU.png

Creating server function
muGCbyL.png

Server list function
vxsnYri.png

Special Considerations for MRTK Scene system?

$
0
0
I managed to get my previous issue resolved by making sure the scene names were the same.

However when loading scenes in the Hololens, lots of things broke and we had to start using the MRTK Scene System. which fixed the things that broke but now we are back to loading into different rooms.

The scene system works by having a manager scene that holds all the items you want to be persistent in your game(HUD, playspace etc) and then uses additive loads to get items from other scenes. This means that the manager scene is usually the active scene and would cause issues when joining rooms. I wrote a script that makes it so that after loading a scene that scene becomes the active scene in order to bypass that but it still loads into another room.

Sync IK

$
0
0
Can you tell me how it is easier and best to synchronize ik?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class PlayerIKSystem : MonoBehaviourPunCallbacks {

    [Header("IK Parametres")]
    [Range(0f, 1f)] public float lookWeight;
    [Range(0f, 1f)] public float bodyWeight;
    [Range(0f, 1f)] public float headWeight;
    [Range(0f, 1f)] public float eyesWeight;
    [Range(0f, 1f)] public float clampWeight;

    [Header("Targets")]
    public Transform lookTarget;

    //[Header("Other Components")]
    Animator playerAnimator;
    PhotonView PV;

    private void Awake()
    {
        PV = GetComponent<PhotonView>();
    }

    private void Start()
    {
        playerAnimator = GetComponent<Animator>();
    }

    private void OnAnimatorIK()
    {
        playerAnimator.SetLookAtWeight(lookWeight, bodyWeight, headWeight, eyesWeight, clampWeight);
        playerAnimator.SetLookAtPosition(lookTarget.position);
    }

}

how to Combine between playfab and photon friend's info

$
0
0
Hi, I am using pun 2 and playfab. I did that every time you add a new friend it adds him to a playfab list, this is good because I can add a friend in any time, not like pun 2 but I can't see if friends are online and get the friends room name(photon option). the problem is that I convert from playfab to photon. is there a way to do it?
here is my playfab code
```
private void DisplayPlayfabFriends(List<PlayFab.ClientModels.FriendInfo> friendCache)
{
foreach (PlayFab.ClientModels.FriendInfo f in friendCache)
{
bool isfound = false;
if(myfriends != null)
{
foreach (PlayFab.ClientModels.FriendInfo g in myfriends)
{
if (f.FriendPlayFabId == g.FriendPlayFabId)
{
isfound = true;
}
}
}
if(isfound == false)
{
UIFriend listing = Instantiate(uiPrefab, container);
if(listing != null)
{
listing.Initialize(f);
listing.friendNameText.text = f.TitleDisplayName;

}
}
}
myfriends = friendCache;
}
```


here is the photon code
```

public void Initialize(Photon.Realtime.FriendInfo friendInfo)
{
info = friendInfo;
roomName = $"{infophoton.UserId}";
friendNameText.text = $"{info.UserId}";

if (infophoton.IsOnline)
{
onlineImage.color = onlineColor;
}
else
{
onlineImage.color = offlineColor;
}
}
```
how to Combine between them both?

What is a good way to reference instantiated objects from other scripts?

$
0
0

I'm instantiating my player and then instantiating a camera and assigning it to the player. I'm hoping to use the camera attached to the player in another script so that the health bar is facing the same direction as the camera but am having a hard time thinking of a good way to reference the instantiated camera assigned to the player. Any thoughts on a good way to do this?

onPhotonInstantiate not working

$
0
0
I am trying to rename network instantiated objects for all clients using on photon instantitae but its not working,and onphotoninstantitiate is not being called ,I have also implemented Interface IPunInstantiateMagicCallback.BUt its not working, Can anyone help me out.
Here is the code snippet:

public class PlacePlayers : MonoBehaviourPun,IPunInstantiateMagicCallback
{
public GameObject playerPieceBlue;
public GameObject playerPieceGreen;
public GameObject[] greenPieces = new GameObject[9];
public GameObject[] bluePieces = new GameObject[9];

void Start()
{
if (PhotonNetwork.IsMasterClient) {
FirstInitializeBluePeices();
}
if (!PhotonNetwork.IsMasterClient)
{
FirstInitializeGreenPeices();
}
}

public void OnPhotonInstantiate(PhotonMessageInfo info)
{
//not getting called !!!!!
}

public void FirstInitializeBluePeices() {

for (int i = 0; i < GreenPos.Length; i++)
{
object[] data = { i, "blue" };
bluePieces = PhotonNetwork.Instantiate(playerPieceBlue.name, BluePos, Quaternion.identity,0,data);
}
}


public void FirstInitializeGreenPeices()
{
for (int i = 0; i < GreenPos.Length; i++)
{

object[] data = { i, "green" };
greenPieces = PhotonNetwork.Instantiate(playerPieceGreen.name, GreenPos, Quaternion.identity,0,data);
}
}

Multiple scene loading issue

$
0
0
Hi,

I'm doing additive scene loading to load two scenes. The first time I try and join a room using
PhotonNetwork.JoinRandomRoom
everything goes fine. However, once I leave the room using
PhotonNetwork.LeaveRoom
and try to join a room again the scene count keeps doubling. Any help would be appreciated.
https://imgur.com/a/CuFwMjE

PUN2 Webgl PeerCreated Stuck Problem

$
0
0
Hi,
Im kinda familiar with Photon. I use Pun 2.21 and Unity 2019.4.
My problem is next. I built for webgl for itch.io and the process is stuck at "peer created" status.

I have already tried change to TCP,Websocket, WebSocket Secure,... i even tried some port, but i stayed at 0. "usenameserver" is ticked.
I modified websocket sharp .. webgl is ticked. ( I had to be able to build webgl)

I would be grateful any idea what can cause this problem.
(In editor it works just fine)
Thank you for your replies

join with friend to random room

$
0
0
hey !
I'm trying to make a situation where I can connect with a friend to an existing room or create a new room with him together (not a private room) that if another pair of players want to enter together they can.

I read here: https://doc.photonengine.com/en-us/pun/current/lobby-and-matchmaking/userids-and-friends

But I did not understand one thing.
When I try to connect to an existing room for example, and I enter my friend's ID in the room entry function to save space for him, how can my friend find the space reserved for him?

I'm trying to create a game like Fortnite that I can enter a random room with more people and with a friend or more.

Thanks for the help.

2D when instantiate enemy, at my top side, but at another player's bottom side

$
0
0
Thanks for browsing my question, this game is my company's big project. Sorry for my poor English.
My game is 2D and only two players. Place I need to defend is on my bottom screen, and on another player's top screen. Place another player need to defend is on my top screen, and on another player's bottom screen. Now, I instantiate an enemy, is can run on my top screen, but run on another player's top screen, too. I need my created enemy run on my top screen, and run on another player's bottom screen, that is "mirror" the game.

I have searched a good manner, but it will make something wrong. Make one player's camera view whole world from the other side, but one player will view all sprites reverse.

Thanks a lot. Appreciate!

JoinRandomRoom does nothing and gives sometimes an error message

$
0
0
Good day everyone,

im trying to join a random room but nothing happens. Sometimes Il get the following error message: JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedToMaster.

My code:
public class Launcher : MonoBehaviourPunCallbacks {
    public static Launcher launcher;

    [Header("Room Settings")]
    public byte maxPlayersPerRoom;

    [Header("Dependencies")]
    public GameObject btnMultiplayer;
    public GameObject btnJoinRandomRoom;
    public GameObject btnLeaveRoom;
    public GameObject btnDisconnect;
    public GameObject lblConnecting;

    private string gameVersion;

    private void Awake() {
        Debug.Log("Network: Trying to initialize launcher");
        launcher = this;
        gameVersion = "1";
        PhotonNetwork.AutomaticallySyncScene = true;
        Debug.Log("Network: Launcher initialized");
    }

    public void Connect() {
        Debug.Log("Network: Trying to connect to server");
        SetLauncherElementsVisiblity(lblConnectingActive: true);
        PhotonNetwork.ConnectUsingSettings();
        PhotonNetwork.GameVersion = gameVersion;
    }

    public override void OnConnectedToMaster() {
        Debug.Log("Network: Successfully connected to master server");
        SetLauncherElementsVisiblity(btnJoinRandomRoomActive: true, btnDisconnectActive: true);
    }

    public void JoinRandomRoom() {
        Debug.Log("Network: Trying to join a random room");
        SetLauncherElementsVisiblity();
        PhotonNetwork.JoinRandomRoom();
    }

    public override void OnJoinedRoom() {
        Debug.Log("Network: Successfully joined a room");
        SetLauncherElementsVisiblity(btnLeaveRoomActive: true);
    }

    public override void OnJoinRoomFailed(short returnCode, string message) {
        Debug.LogFormat("Network: Joining a random room failed\nError Code: {0}\nError Message: {1}", returnCode, message);
        CreateRoom();
    }

    public void CreateRoom() {
        Debug.Log("Network: Trying to create a new room");
        string roomName = "Room " + Random.Range(0, 1000);
        RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = maxPlayersPerRoom };
        PhotonNetwork.CreateRoom(roomName, roomOps);
    }

    public override void OnCreatedRoom() {
        Debug.Log("Network: Successfully created a new room");
        SetLauncherElementsVisiblity(btnLeaveRoomActive: true);
    }

    public override void OnCreateRoomFailed(short returnCode, string message) {
        Debug.LogFormat("Network: Creating a new room failed\nError Code: {0}\nError Message: {1}", returnCode, message);
        CreateRoom();
    }

    public void LeaveRoom() {
        Debug.Log("Network: Trying to leave the room");
        SetLauncherElementsVisiblity();
        PhotonNetwork.LeaveRoom();
    }

    public override void OnLeftRoom() {
        Debug.Log("Network: Successfully left the room");
        SetLauncherElementsVisiblity(btnJoinRandomRoomActive: true, btnDisconnectActive: true);
    }

    public void Disconnect() {
        Debug.Log("Network: Trying to disconnect from server");
        SetLauncherElementsVisiblity();
        PhotonNetwork.Disconnect();
    }

    public override void OnDisconnected(DisconnectCause cause) {
        Debug.Log("Network: Successfully disconnected from server");
        SetLauncherElementsVisiblity(btnMultiplayerActive: true);
    }

    private void SetLauncherElementsVisiblity(bool btnMultiplayerActive = false, bool btnJoinRandomRoomActive = false, bool btnLeaveRoomActive = false, bool btnDisconnectActive = false, bool lblConnectingActive = false) {
        btnMultiplayer.SetActive(btnMultiplayerActive);
        btnJoinRandomRoom.SetActive(btnJoinRandomRoomActive);
        btnLeaveRoom.SetActive(btnLeaveRoomActive);
        btnDisconnect.SetActive(btnDisconnectActive);
        lblConnecting.SetActive(lblConnectingActive);
    }
}

Most of it are just callbacks to catch. I call the method JoinRandomRoom with a button.

I will appreciate every help.

Have a good day!

First and third person

$
0
0

Hi,I have a question. In my game , player can play in first and third person.When i play in third person i just put animation controller to be tracked by the photon view and it is fine.but when i use the first person,I want to be able to catch animations from the local player and send animations to others.

Attempting to rejoin room and getting "User does not exist in this game".

$
0
0
I have a room set up as -
RoomOptions roomOptions = new RoomOptions();
                roomOptions.IsVisible = false;
                roomOptions.MaxPlayers = 5;
                roomOptions.PlayerTtl = 3600;
                roomOptions.PublishUserId = true;
                PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);

I have two players in the room and then I close one of them by stopping the play mode in Unity).
Upon loading the game again I do -
string userId = PlayerPrefs.GetString("userId");
            if (userId != "")
            {
                PhotonNetwork.AuthValues = new AuthenticationValues(PlayerPrefs.GetString("userId"));
            }
            PhotonNetwork.ConnectUsingSettings();

This seems to work as I get the same UserId as before.
However, when I user "RejoinRoom" It fails with the message "User does not exist in this game".

The room name is correct.

Please assist.

Binary Protocol/Network Package Layout


Tower who own it will fire, but will not fire if don't own it (only two players)

$
0
0
My Tower GameObject have two child, one for targeting and one for firing.
I use OnTriggerEnter2D(2D game) to decide if tower fire.
At first, place tower work fine, it shows immediately on two player's screen, no matter who create the tower.
However, only player who own the tower will target and fire. Furthermost, I put some debug.log in child of tower gameobject's OnTriggerEnter2D, it didn't show any message in my console.
Thank you for answering. Appreciate!

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 connect to Photon cloud in android devices.

$
0
0
In my app, I try to connect to the Photon cloud. In my Unity Editor, I am able to connect to the server and do what I want it to do. However, when I build the application for android devices, it does not connect to the server and I don't know why.

The type or namespace "pun" does not exist in the namespace "Photon" error

$
0
0
Hey all, I am following a tutorial on how to use Photon in Unity. I followed the tutorial step by step till I got stuck on this error. For whatever reason it cannot find the "pun" namespace. I have tried the fix on where I have to drag some folders around but that didnt work either. Does anyone know a fix?

AI bots destroying when master client leaves from room

$
0
0
Hi. I developing a multiplayer first person shooter game with Unity3D. I have bots(AI) in game. The all bots are managed by master client. When master client is leaved from room and master switched to an another player, all bots are destroying. How can I prevent this? I know it is normal because the owner of bots is leaving from game and they are destroying with him. But I want prevent this. I want be switch all bots owner to new master client when master client is changed. Can anyone help me?
Viewing all 8947 articles
Browse latest View live


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