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

PUN 2 not working on WebGL

$
0
0
Connecting to master is completely fine. but whenever it tries to load in Players from inside a room it gives me this error:

An Error occured running the Unity Content on this Page. see your browser JavaScript Console for more info. The Error was: Uncaught abort(224). You can take a look for yourself here:https://nerfski.itch.io/multiplayer-testing

When is OnPhotonSerializeView Called?

$
0
0
Hello, I am trying to save bandwidth and reduce network traffic by only sending messages over OnPhotonSerializeView when necessary. When I am observing only one script it works exactly how I want it to (the receiver's OnPhotonSerializeView is called whenever the sender sends something) but when I observe multiple scripts the receiver keeps trying to read the stream even if the sender has not sent anything so I get the IndexOutOfBounds exception.
The photon view's setting is on reliable data compressed.

Here is the code of the script that is working (this is the only script being observed)

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if ((Vector2)transform.position == SentPosition)
return;
if (stream.IsWriting && photonView.IsMine)
{
SentPosition.x = transform.position.x;
SentPosition.y = transform.position.y;
stream.SendNext(SentPosition);
}
else if (stream.IsReading && !photonView.IsMine)
{
transform.position = (Vector2)stream.ReceiveNext();
}
}

Im not sending my position if it is the same and at that time the client on the other side doesnt try to receive anything.
This is really useful because this object can only be at two places and then stays there

Here is the code that is giving me the OutOfBoundsException (There are two other scripts being observed on this object)

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting && GobblerID != int.MinValue)
{
stream.SendNext(GobblerID);
GobblerID = int.MinValue;
}
else if (stream.IsReading)
{
GobblerID = (int)stream.ReceiveNext();
}
}

Im trying to send GobblerID(int) only when it gets updated but the receiver keeps trying to receive it even though it has not been sent


I have been stuck with this for a long time any help will be MUCH APPRECIATED. I've tried to give all details relevant pls let me know if you want to have any other detail.

The photonView settings are exactly similar the only difference is that i have multiple scripts being observed.

LoadBalancingClient and RPC calls

$
0
0
So in order to keep track of the online status of friends I create a LoadBalancingClient `client` and use it to connect to a region master server, there I can call OpFindFriends(). I create a room by calling client.OpCreateRoom(), but when I try to make RPC call through: PhotonView.RPC(...), I get error because CurrentRoom is null. How do I execute a RPC through my LoadBalancingClient?

Players can't connect to each other, no response code

$
0
0
After PhotonNetwork.JoinLobby() we should receive 2 callbacks: OnJoinedLobby() and OnRoomListUpdate() . OnOperationResponse doesn't receive response with code, which corresponds OperationCode.GetGameList along with room info. We receive response with OperationCode.JoinLobby code, though

Pls help, game became unplayable. Everything worked good ~1 week ago, haven't changed anything from then.

Sync UI buttons and interactable states

$
0
0
Hello All ! Am working in a two player game where UI elements are same. Whereas, if certain conditions are satisfied for one player then he can access the UI elements like he can click on buttons else the button should not be interactable? How can i achieve this?

EU and USW Region Ping no response

$
0
0
Looking for some help with a live WebGL game that is having problems with pinging regions.

Our game pings 4 regions but is currently not getting a response for EU or USW. Players can still manually connect to these regions. This is happening for our current live WebGL build. On debugging in Unity I can see that there is definetely no response from those regions when I reset the region preferences.

We broke through our 1100 CCU cap and have increased it a few hours ago. Is this related? It seems maybe likely.

Main menu after login

$
0
0
Hello! I have been using unity3d for a few years now, now I want to try making a simple multiplayer card game.
And I have difficulties.

Question:
I want do a login and later see main menu where i can choose kind of game (like clash royale for example) or prepare your own deck.
How do it? And the best practice? (pseudocode or conceptual information, i not ask a right code)
(I don't think you need to create a room for the main menu)

Does FindFriends only work when not in a room?

$
0
0
I have FindFriends working when I am not in a room, and I call it periodically to get the online status of friends. Works fine before I join a room. However when I create/join a private (IsVisible = false) room, it doesn't work anymore. I would like to invite friends to the private room once I'm already in it. I get these two errors instead: Operation failed: OperationResponse 222: ReturnCode: -2 (Unknown operation code). Parameters: {} Server: GameServer UnityEngine.Debug:LogError(Object) NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1544) 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) FindFriends failed to apply the result, as a required value wasn't provided or the friend list length differed from result. UnityEngine.Debug:LogError(Object) NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1922) In NetworkingPeer line 1906, both lists are empty: i.e. onlineList and roomList are both null.

How to Join to your friend's room

$
0
0
Hi guys, I want to join to my friend room, first I join to a lobby and create a room(of course I connect to photon first and to playfab) then when I click in my friend, I check if photon is connected and join his room as you can see here:
if (PhotonNetwork.IsConnected)
{
Debug.Log($"Joining Friend's Room: {roomName}");
PhotonNetwork.JoinRoom(roomName);
}
else
Debug.Log("not connected so can't join");
then I want to see if he joined so I have playerlisting.

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

public class PlayerListing : MonoBehaviourPunCallbacks
{
[SerializeField]
public Transform content;
[SerializeField]
public UiFriendRoom _uifriendroom;

private List<UiFriendRoom> _Uifriend = new List<UiFriendRoom>();

private void AddPlayerListing(Player player)
{
UiFriendRoom uIFriend = Instantiate(_uifriendroom, content);
if (uIFriend != null)
{
uIFriend.SetPlayerInfo(player);
_Uifriend.Add(uIFriend);
Debug.Log("OnPlayerEnteredRoom was called");
}
}

private void GetCurrentRoomPlayers()
{
Debug.Log("Trying to get the current room's players");
Debug.Log($"Are we in a room though: {PhotonNetwork.InRoom}");
if (!PhotonNetwork.InRoom) return;
foreach (KeyValuePair<int, Player> PlayerInfo in PhotonNetwork.CurrentRoom.Players)
{
Debug.Log("OnPlayerEnteredRoom was called");
AddPlayerListing(PlayerInfo.Value);
}
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
AddPlayerListing(newPlayer);
Debug.Log("OnPlayerEnteredRoom was called");

}
public override void OnJoinedRoom()
{
GetCurrentRoomPlayers();
}



public override void OnPlayerLeftRoom(Player otherPlayer)
{
int index = _Uifriend.FindIndex(x => x.Player == otherPlayer);
if (index != -1)
{
Destroy(_Uifriend[index].gameObject);
_Uifriend.RemoveAt(index);
Debug.Log("why did you left the room?");
}
}



public override void OnLeftRoom()
{
Debug.Log("left Room");

}
}
I do not know if the problem is with the joining rooms or with the PlayerListing, it doesn't show the friend's in the player listing. and I have this error when I press mu friend button(to join him) : JoinRoomfailed. client is on game server(Must be master server for matchmaking) and ready.wait for callback: Onjoinedlobby or Onconnected to master.
pls help :smile:

What is the recommended networking speed?

$
0
0
What would the recommended internet speed for the clients be, for the server to work fine for them?

RoomInfo.CustomRoomProperties is empty on lobby?

$
0
0
Here's how I create the room:
public void CreateRoom(string name, string mode, string map, int maxPlayers) {
	popupCreateLobby.SetActive(false);
	popupConnecting.SetActive(true);

	ExitGames.Client.Photon.Hashtable roomSettings = new ExitGames.Client.Photon.Hashtable() {
		{ "name", name }, { "mode", mode }, { "map", map }
	};

	string[] lobbyProperties = { "name", "mode", "map" };

	RoomOptions options = new RoomOptions();
	options.IsVisible = true;
	options.IsOpen = true;
	options.MaxPlayers = (byte) maxPlayers;
	options.CustomRoomPropertiesForLobby = lobbyProperties;
	options.CustomRoomProperties = roomSettings;
	PhotonNetwork.CreateRoom(null, options, TypedLobby.Default);
}
Here's how I display the information. I call this when the game received OnReceivedRoomListUpdate.
public void SetRoomInfo(RoomInfo roomInfo) {
	this.roomInfo = roomInfo;

	Debug.Log(roomInfo.ToStringFull());

	textGameName.text = (string) roomInfo.CustomProperties["name"];
	textGameMode.text = (string) roomInfo.CustomProperties["mode"];
	textMapName.text = (string) roomInfo.CustomProperties["map"];
	textPlayerCount.text = roomInfo.PlayerCount + " / " + roomInfo.MaxPlayers;
}
The log displays:
Room: 'xxxx' visible,open 1/0 players.
customProps: {}
As you can see, the customProps is empty even though I set them properly when I created the room. What gives?

how can i show enabling and disabling particular component over the network?

$
0
0
how can i show enabling and disabling particular component over the network? if particular player is disabled the collider

Get player number in room with ViewID

$
0
0
I have this code...
other.gameObject.GetComponent<PhotonView>().ViewID

Assuming PUN has a reliable list of players that does not change and can be traversed I want to find out what number in that list they are, if that makes sense.

So I have
Player1 VIEWID: 1001
Player2 VIEWID: 2001
Player3 VIEWID: 4001
Player4 VIEWID: 5001

I want to use the ViewID to find out that ViewID 4001 is 3rd in that list. I hope that all makes sense and is easily possible.

Thanks

Beginner Help! How to access a Component from the other player in the same room

$
0
0
Hi All!

Beginner Unity user here. I am making a simple multiplayer card game prototype. Two players join the same room (Max num of players in room set to 2). Game scene is loaded.

The game scene has a logic in start method, which randomly picks a list of sprites and displays it on screen. The problem is for both the players the list of sprites are different. (meaning the scene is independently loaded in both devices and random logic is causing different sprites)

Is there some way that the second user who connects to the room access the list of sprites generated for the master in the room? so that the sprites displayed for both the users are the same.

Appreciate your help

Thanks,
Karthik

InvalidCastException ViewTransform. Need help!

$
0
0
InvalidCastException: Specified cast is not valid.
Photon.Pun.PhotonTransformView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformView.cs:87)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:680)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:670)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1817)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2188)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3142)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)

this is the only thing holding my game back. please help.

Game Restart

$
0
0
when i playing game my game is restart and second player is win

OnEvent is not called when event is raised

$
0
0
i literally just copy pasted codes from pun v2 website

here's my script

using Photon.Pun;
using UnityEngine;
using ExitGames.Client.Photon;
using Photon.Realtime;

public class TestEvent : MonoBehaviourPunCallbacks
{
public const byte MoveUnitsToTargetPositionEventCode = 12;
public override void OnEnable() { PhotonNetwork.AddCallbackTarget(this); }
public override void OnDisable() { PhotonNetwork.RemoveCallbackTarget(this); }
private void Start()
{
Debug.Log("started");
SendMoveUnitsToTargetPositionEvent();
}
private void SendMoveUnitsToTargetPositionEvent()
{
string content = "hello";
RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All };
PhotonNetwork.RaiseEvent(MoveUnitsToTargetPositionEventCode, content, raiseEventOptions, SendOptions.SendReliable);
Debug.Log("string 1 = " + content);
}
public void OnEvent(EventData photonEvent)
{
Debug.Log("reached here");
byte eventCode = photonEvent.Code;

if (eventCode == MoveUnitsToTargetPositionEventCode)
{
string data = (string)photonEvent.CustomData;
Debug.Log("string2 = " + data);
}
}
}


to set up PUN2 in unity i just made an app in photon database and copy pasted app id in unity, i didnt do anything else.

what am i doing wrong here ?

Instantiating a gameobject and syncing it

$
0
0
Hi There, I've spent months working through PUN2 documentation and tutorials and with much trial and error I am at a point where both players connect to the same room and the game scene launches.

There are no moving parts other than a timer and a score that I need to send/receive. I have added IPunObservable and added the necessary gameobjects that need to be sent/recieived as the example in the basics tutorial.

What happens: The timer only appears on the MasterClient (as it would) but does not appear on the other players game.

Photon registers the Photonviews applied.

What I want: The timer to be synced and instantiated from the Masterclient to all players

help with photon pls

$
0
0
hi there, I kinda need help with a lot of things so if someone can help me with will be amazing, thx

DefaultPool fails to load my prefab once or twice then it works

$
0
0
I updated to Unity 2020 from 19 because of an error that wouldn't let me open my project. I also removed all of the appdata to try and fix the problem. Since then, I have many issues but the most concerning one is that when I open the project and press play it fails to load my prefabs that are located in the root of a resources folder (that was working perfectly before). I try again and it fails again. Then usually around the 3rd time of trying it works perfectly fine.

How do I fix this?
Viewing all 8947 articles
Browse latest View live


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