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

Need Help with the OperationResponse 252 / 253

$
0
0
I scripted a code like below.

I can create a room and can tested it with myself when i opened the game twice and everything is ok.
But if a friend create the game or joined my game . it works a few second for us both and then after different amount of seconds he kicked out everytime of the gameroom with the Operation Response 252 and sometimes 252+ 253.
Need help with this.

Launcher Code
public class LauncherMaster : MonoBehaviourPunCallbacks
{// MasterScript for Menu
    public static LauncherMaster Instance;


    [SerializeField] private string versionName = "0.1";
    [Header("UIs")]
    [SerializeField] GameObject connectingUI;
    [SerializeField] GameObject usernameUI;
    public GameObject mainMenuUI;
    [SerializeField] FindRoomsUI lobbyUI;
    [SerializeField] GameObject errorUI;
    [Header("Inputs")]
    [SerializeField] TMP_InputField usernameInput;
    [SerializeField] TMP_InputField createGameInput;
    [SerializeField] TMP_InputField joinGameInput;
    [Header("Buttons")]
    [SerializeField] TMP_Text errorText;
    [SerializeField] TMP_Text nickNameText;
    [SerializeField] GameObject startButton;
    [SerializeField] Toggle togglePublic;



    private void Awake()
    {
        Instance = this;
        connectingUI.SetActive(true);
        PhotonNetwork.ConnectUsingSettings();
        Debug.Log("Connecting...");
    }



    public override void OnConnectedToMaster()
    {
        PhotonNetwork.JoinLobby();
        Debug.Log("Connected");
    }


    public override void OnJoinedLobby()
    {
        connectingUI.SetActive(false);
   
        // wenn nickname schon vorhanden
            //usernameUI.SetActive(false);

            usernameUI.SetActive(true);
       
        mainMenuUI.SetActive(true);
        Debug.Log("Joined Lobby");
    }

    public void ChangeUserNameInput()
    {
        if(usernameInput.text.Length >=4)
        {
            startButton.SetActive(true);
        }
        else
        {
            startButton.SetActive(false);
        }
    }

    public void SetUserName()
    {
        usernameUI.SetActive(false);
        //PhotonNetwork.playerName = usernameInput.text;
        PhotonNetwork.NickName = usernameInput.text;
        nickNameText.text = "Nickname: " + PhotonNetwork.NickName;
    }

    
    public void CreateGame()
    {
        if (string.IsNullOrEmpty(createGameInput.text))
        {
            Debug.Log("Type a roomName");
            return;
        }

        if(togglePublic.isOn)
        {
            RoomOptions roomOptions = new RoomOptions()
            { 
                MaxPlayers = 10
            };
        }
        if (!PhotonNetwork.IsMasterClient)
        {
            Debug.LogError("PhotonNetwork : Trying to Load a level but we are not the master Client");
        }
       
        if (togglePublic.isOn)
        {

            if (PhotonNetwork.CreateRoom(createGameInput.text, new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 10 }, null))
            {
                connectingUI.SetActive(true);
                print("Creating room successfully send");

            }
            else
            {
                print("Creating room failed to send");
            }
            ;
        }
        else
        {
            if (PhotonNetwork.CreateRoom(createGameInput.text, new RoomOptions() { IsVisible = false, IsOpen = true, MaxPlayers = 10 }, null))
            {
                connectingUI.SetActive(true);
                print("Creating room successfully send");
            }
            else
            {
                print("Creating room failed to send");
            }
        } 
        ;
    }
    public override void OnJoinedRoom() //if joined or create
    {
        PhotonNetwork.AutomaticallySyncScene = true;
        if (PhotonNetwork.IsMasterClient)
        {
           
            PhotonNetwork.LoadLevel("Arena");
            
        }
           
       // print("Room created successfully");
    }
    public override void OnJoinRoomFailed(short returnCode, string message)
    {
        Debug.Log("Roomname doesn´t exsist");
    }

    public override void OnCreateRoomFailed(short returnCode, string message)
    {
        print("create room failed " + message);
        errorUI.SetActive(true);
        errorText.text = "Room creation failed " + message;
    }


    public void JoinRoom()
    {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 10;
        PhotonNetwork.JoinRoom(joinGameInput.text);
        connectingUI.SetActive(true);
        PhotonNetwork.AutomaticallySyncScene = true;
    }
[b]    public void JoinRoomInfo(RoomInfo info)
    {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 10;
        PhotonNetwork.JoinRoom(info.Name);
        connectingUI.SetActive(true);
        PhotonNetwork.AutomaticallySyncScene = true;
    }[/b]

    public void QuitGame()
    {
        Application.Quit();
    }
}

Room Script
public class RoomManager : MonoBehaviourPunCallbacks
{//Check the right Scene
    public static RoomManager Instance;
    public PlayerManager playerManager;

    private void Awake()
    {
        if(Instance)
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);
        Instance = this;
    }


    public override void OnEnable()
    {
        base.OnEnable();
        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    public override void OnDisable()
    {
        base.OnDisable();
        SceneManager.sceneLoaded -= OnSceneLoaded;
    }

    void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
    {
        if(scene.buildIndex == 1) //We´re in the game scene
        {
           playerManager = PhotonNetwork.Instantiate("PlayerManager", Vector3.zero, Quaternion.identity).GetComponent<PlayerManager>();
           RoomUI roomUI = FindObjectOfType<RoomUI>();
           roomUI.player1StartButton.GetComponent<Button>().onClick.AddListener(playerManager.SpawnPlayer1);
           roomUI.player2StartButton.GetComponent<Button>().onClick.AddListener(playerManager.SpawnPlayer2);
        }
    }

    public override void OnDisconnected(DisconnectCause cause)
    {

        Debug.LogWarningFormat("Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
    }


}

Why does my photon view have no owner/isMine false?

$
0
0
Hello, ive been instantiating players and had no problem; but recently I needed to switch to laoding assets from asset bundles. Because of this I need to do manual instantiation. I've copied the code straight from photons documentation here: https://doc.photonengine.com/en-us/pun/current/gameplay/instantiation and basically replaced using photonnetwork.instantiate with that. I use the code from the link exactly as is. When i load into a room everything works fine at first; the player can walk around and do everything within the "isMine" locked portion of the players code; even though when I look at the player prefab in inspector it says isMine is false and owner is null(both 'controller' and 'creator' get set as me correctly). And then when i specifically click on a child object of the playerprefab in inspector suddenly i cant control the player anymore. so presumably the "isMine" suddenly realizes that is indeed false.

My question is how do i make the owner not null, and make isMine true since I am the creator who instantiated the object? Any help would be appreciated, this has been driving me nuts for 2 days now.

heres a link to the full code: https://pastebin.com/q90FP3zH
the relevant part is basically just the SpawnPlayer() method.



When CAS fails, I want to get which key failed.

$
0
0
I want to use CAS to implement who gets the item on the stage.
Based on various samples, I was able to implement it in the following way.
    public bool SetCustomPropertySafe(this Room room, string key, object newValue, WebFlags webFlags = null)
    {
        Hashtable newProps = new Hashtable(1) {{key, newValue}};
        Hashtable oldProps = new Hashtable(1) {{key,  PhotonNetwork.CurrentRoom.CustomProperties[key]}};
		return PhotonNetwork.CurrentRoom.SetCustomProperties(newProps, oldProps);
    }
	
    private void OnEnable()
    {
        PhotonNetwork.NetworkingClient.OpResponseReceived += NetworkingClientOnOpResponseReceived; 
    }

    private void NetworkingClientOnOpResponseReceived(OperationResponse opResponse)
    {
        if (opResponse.OperationCode == OperationCode.SetProperties &&
            opResponse.ReturnCode == ErrorCode.InvalidOperation)
        {
            // cas failure
            // TODO: Which key failed?
            Debug.Log(opResponse.DebugMessage);
            Debug.Log(opResponse.ToStringFull());
            Debug.Log(opResponse.Parameters.ToStringFull());
        }
    }

However, what I want to do is to determine which key failed when multiple keys (items) are registered at the same time using OpResponseReceived (OperationResponse opResponse).

However, I'm having trouble with opResponse not containing the value of the failed key.
DebugMessage contains the string "(CAS update failed: property='item1' has value='1')" which is the information of the failed key.
However, I am having trouble identifying the opResponse.Parameters because it does not contain any value.
How can I include the value of the failed key in Parameters?
Or how can I find out the value of the failed key in a different way?

Crazy house in PUN room.

$
0
0
Hi!

Sometimes I go into an existing room (where players are already playing) and there is some horror happening. This horror lasts for a while (usually from 30 seconds to a minute), and then everything normalizes. Not enough time to record the video, but I'll try next time. Although it's easy to imagine this situation (example in this video, only very quickly: https://radikal.ru/video/bWm0pCBilsq ).

In general, all the objects (PhotonView) begin to move around the location furiously and jerkily as "Figaro here, Figaro there"... They flash at different coordinates, do something quickly and then disappear again, appear in different places, and so on. After a while, this circus ends and the game goes on as usual.

May be (IMHO) RPC commands accumulate on the PUN server (in a bufer) while MasterClient is playing, and then all these commands are quickly sent to those who join this room.

BUT! I use in the project only:

RpcTarget.Others
Sends the RPC to everyone else. This client does not execute the RPC. Player who join later will not execute this RPC.

NOT: RpcTarget.AllBuffered or RpcTarget.OthersBuffered.

Please tell me what the problem may be and how can I get rid of this in my game?

Thanks!

Network icons in Game

$
0
0
Hi!

I wanted to add a system in my game like in most online games, when you have a poor connection (like latency or packet loss) some icons are displayed on screen to tell the player (speedometer for latency or dotted squares for packet loss).
I already managed to do the latency icon by getting the ping of the player, but I wanted to know if there was a way to do the same for packet loss? Is there a way to know how many packets were lost before a RPC arrived or when sending data by stream with OnPhotonSerializedView?

Thanks

One Mapp(One Master) and every Player join on the Master

$
0
0
Hello,

I have read the documentation . Only I can not figure out one thing. I do not want to have multiple lobbies, but I want to have a master (server build) on which then each player can join. This is because I want to make an open map on which everyone can play multiplayer. How can I implement this. Which methods and classes do I need for the server (master) and which for the player (client).
or where can I read about it ?

Thanks a lot :)

Translated with www.DeepL.com/Translator (free version)

I have tried to connect to the server and I get this error:

$
0
0
Failed parsing address: 
UnityEngine.Debug:LogError(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2504)
ExitGames.Client.Photon.IPhotonSocket:Connect() (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/IPhotonSocket.cs:132)
ExitGames.Client.Photon.SocketUdp:Connect() (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/SocketUdp.cs:74)
ExitGames.Client.Photon.EnetPeer:Connect(String, String, String, Object) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:258)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String, String, Object, Object) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1502)
Photon.Realtime.LoadBalancingClient:ConnectToMasterServer() (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:959)
Photon.Pun.PhotonNetwork:ConnectToMaster(String, Int32, String) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1236)
Photon.Pun.PhotonNetwork:ConnectUsingSettings(AppSettings, Boolean) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1166)
Photon.Pun.PhotonNetwork:ConnectUsingSettings() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1103)
tutoriales.multiplayer.AutoLobby:Connect() (at Assets/scripts/AutoLobby.cs:22)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.18f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

My Game Can NOT Connect To Photon,please help me[PUN1]

$
0
0
my porject used to be good in few mouth ago,but now It can not connect to photon.
i tried to ues PhotonNetwork.GetPing() but it allways get 200ms.
i dont know why,and i did not chance any thing.

the only thing i did is re-build my porject.can it be reason?
i jioned a game-making competition by this porject ,but it does not work now,please help me.

Failed to connect to server after testing each known IP

IPv6 for Unity iOS Exports

$
0
0
Apple now requires iOS apps to support pure IPv6 connections. We tested PUN v1.75 and it supports IPv6, including the "Best Region" setting. If you use the Photon Cloud, you only have to make sure your PUN version is up to date. If you run a Photon Server, you need to use a recent 4.x server.

Test All Builds

Unity's support for IPv6 begins with 5.3.4p4. They posted about adding IPv6 support. Several versions of Unity do not successfully support IPv6, so you should test each build. If you get a client-side error like this, your client needs an update; Connect() to 'x.x.x.x' failed: System.Net.Sockets.SocketException: Network is unreachable in a IPv6 network.

Test Procedure

Read "Test for IPv6 DNS64/NAT64 Compatibility Regularly" to learn how to test IPv6 support easily. We do this for PUN before release. Make sure there is not some other plugin failing!

Handling Rejections

We know that some apps got rejected, despite using PUN v1.75 or newer. If your app gets rejected, please get in touch with the Apple review team. Point out that you're using PUN and that we and you both tested the networkcode versus their own test procedures. Explicitly point to their own test-description page. Apple suggests:
If the iOS application is successful in working across the macOS NAT64 test environment, then the next step is to submit a bug report. We ask developers to use the Apple Developer Bug Report web page - http://bugreport.apple.com to submit the bug report. The bug report is to indicate that there is some compatibility issue between the app and the App Review test environment. In the bug report, the developer provides evidence that the iOS application worked successfully across the macOS NAT64 test environment by including a packet trace to show the success of the connection process. Note that the bug report is not an indication as to where the problem lies, but the fact that the iOS app works in the test environment and not in App Review is an indication that the app / App Review interaction needs further review. Once the bug report is submitted, there issue is then assigned to investigation by an App Review group. Once a bug report is assigned to App Review, the next thing is to follow up with the bug report by communication with App Review - “appreview@apple.com”. While the email inquiries may not always get a response - all of the correspondence is viewed.

Cloud and Server

The Photon Cloud can not provide public IPv6 addresses in the short term. However, Apple's requirement is only that clients can cope with IPv6 addresses in their network, if that provides "IP translation", as described in their article. For anyone using Photon Server (OnPremise), this means, you can likely continue to run it as IPv4 service. If you want to setup a true IPv6 server, we have some docs for that. Get Photon Unity Networking in the Asset Store.

PUN OpGetRegions with correct AppID fails with Missing value 224 (GetRegionListRequest.ApplicationId

$
0
0
We're using PUN+ 1.76, everything works fine for connecting to regional servers and playing MP games. But when we try to get the region list by calling PhotonNetwork.networkingPeer.OpGetRegions() it always fails with this error:
Operation failed: OperationResponse 220: ReturnCode: -2 (Missing value 224 (GetRegionListRequest.ApplicationId)
). Parameters: {} Server: NameServer
Our steps:
  • - PhotonNetwork.networkingPeer.ConnectToNameServer()
  • - Wait for PhotonNetwork.connectionStateDetailed == ClientState.ConnectedToNameServer
  • - log PhotonNetwork.PhotonServerSettings.AppID to confirm it is set and correct (it is)
  • - PhotonNetwork.networkingPeer.OpGetRegions(PhotonNetwork.PhotonServerSettings.AppID)
  • - PUN logs the error noted above
btw we get the same error if we call other higher level methods while connected to name server, e.g. PhotonNetwork.ConnectToBestCloudServer() The code for OpGetRegions() is simple and I can see it sets the AppID param: parameters[(byte)ParameterCode.ApplicationId] = appId; so no idea what to try next. Is this a server bug? Something we are doing wrong which is giving a confusing error response? Thanks for help!

Noticed today login times are much slower, has anything changed?

$
0
0
Normally it would take about 1 or 2 seconds to login, but today it's been taking around 7-8 seconds. Once we're in it's fine, it just takes a really long time to connect now. I tried with various different regions and same issue.

I also tried running my old builds and the same issue so it's not to do with something I've changed in the game.

I also tried with a new app id.

Anyone else experiencing the same?

Serialization in Photon - StreamBuffer Method

$
0
0
Hello

Thank you for Photon Service. It's very easy to use.
I need so help with the Serialization using StreamBuffer Method.

Indeed I have a large bytes array and I cannot use the classical Byte Array Method:
https://doc.photonengine.com/en-us/pun/current/reference/serialization-in-photon

So I will trying to use the StreamBuffer Method but I don't know how to do.
Example:
public class MyCustomStreamSerialization
{
    public byte[] MyBytes;

    public static short Serialize(StreamBuffer outStream, object obj)
    {
        MyCustomStreamSerialization data = (MyCustomStreamSerialization)obj;
        lock (data)
        {
            outStream.Write(data.MyBytes, 0, 2 * 4);
        }

        return 2 * 4;
    }

    public static object Deserialize(StreamBuffer inStream, short length)
    {
        MyCustomStreamSerialization data = new MyCustomStreamSerialization();
        lock (data)
        {
            inStream.Read(data.MyBytes, 0, 2 * 4);
        }

        return data;
    }

}

Can you help me?

Thank you

Non Resource located network prefabs.

$
0
0
Hi,

I have a request for Photon PUN so you guys can take into consideration, let me explain:

I have a Multiplayer Kit in the Asset Store which uses Photon PUN 2, I have received some similar questions related to the game build size, which is caused by all the content that is included in the Resources folder and since Photon by default requires that any prefab that is instantiated by PhotonNetwork.Instantiate(...) need to be located in a Resources folder, devs can't build these assets in an Asset Bundle or Addressable, so it has to be build-in the main game package causing it to be heavy in size, that is especially a problem for mobile games.

For my own games, I have fixed this by modifying a few lines in Photon PUN code, but for my kit in the Asset Store, since I'm now allowed to include your package, users have to download it from your publisher page so I can't fix it.

So I request the addition of this feature: Add Non-Resourced located prefabs in the PrefabPool of PhotonNetwork in order to be able to instantiate with PhotonNetwork.Instantiate.

That could be optionally and not a replacement for the actual system, of course, let developers that need it used it.

I managed to do this by adding this function:
void RegisterPrefab(string prefabID, GameObject prefab);
in IPunPrefabPool interface, and implemented in the class: public class DefaultPool : IPunPrefabPool (PunClasses.cs) like this:
/// <summary>
        /// Register prefabs to be network instantiated that are not located in a Resources folder.
        /// </summary>
        /// <param name="prefabID">String identifier for the networked object.</param>
        /// <param name="prefab">The prefab to be instantiated.</param>
        public void RegisterPrefab(string prefabID, GameObject prefab)
        {
            if (!this.ResourceCache.ContainsKey(prefabID))
            {
                ResourceCache.Add(prefabID, prefab);
            }
            else
            {
                Debug.LogError($"A prefab was already registered with the key '{prefabID}' make sure you use a unique Key for each prefab or not registered multiple times.");
            }
        }

So I can use like this:
PhotonNetwork.PrefabPool.RegisterPrefab("MyPrefabID", MyPrefab);

Hopefully, you guys take this in consideration and support it by default,
Regards.

Preventing disconnects on moderately unstable networks

$
0
0
Hi folks,

I have a very slow paced game with very long matches, and I need the client to patiently wait out network degradation without disconnecting or otherwise interrupting the game. The game could be played via the post and it would work just to emphasize. :)

I've tried the following:
* adjusting the timeouts to 5mins
* using TCP
* reconnecting after a disconnect

However these don't seem to work well in my tests, the timeout I set doesn't get honored, and catching OnDisconnect and reconnecting leaves the game in an undefined state since lots of things catch the disconnect and start cleaning up.

What would be the recommended approach here?
1. Do I just track down all the components catching the OnDisconnect and put a layer in-between them and do a transparent reconnect?
2. Do I need to change the timeout settings server side for this to work? As that I see the server drops the connection quickly.
3. Any other suggestions?

Any help appreciated!

Thanks!

GetRegions Failed Error ( GetRegions failed. Can't provide regions list. )

$
0
0
I am using PUN 2 in latest version of UFE (Universal Fighting Engine). I am using Photon Cloud Service. I am adding App Id according to the document at https://doc.photonengine.com/en-us/pun/v2/getting-started/initial-setup . But still I am getting following Error.
GetRegions failed. Can't provide regions list. ReturnCode: -2: Empty application id
UnityEngine.Debug:LogError (object)
Photon.Realtime.LoadBalancingClient:DebugReturn (ExitGames.Client.Photon.DebugLevel,string) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2504)
Photon.Realtime.LoadBalancingClient:OnOperationResponse (ExitGames.Client.Photon.OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2734)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:864)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:559)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1837)
Photon.Pun.PhotonHandler:Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:223)
Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:149)

Could you please help me in this.

Photon.Pun.Simple.Internal.TickManager have null

$
0
0
Is this a bug?
I got null reference error at installation.

using win10
unity 2020.2
pun 2.25
photon lib 4.1.4.7

Does anyone have a solution?

Get list room when inside a room other

$
0
0
Hello Everyone!
Hello Photon team!
I have problems likes:
I made a vr app, when launching the app, everyone was put in a shared room, where everyone could chat, meet each other, and then create a private room together, when the room creator (room owner) Then others can not get the list to join, how to get the list of room list?
please help me!
thank you very much!

Unity Photon Rigidbody Addforce Problem

$
0
0
so... I have 2 players and 1 ball, when the player touches the ball, the ball is adding force. in the first player all works fine but in the other player nothing happens. also when the player is touches the ball, the ball is adding force through his script. and also in the start of the game I do InstantiateRoomObject to the ball.

Cannot create room

$
0
0
I use PUN to create multiplayer in my game. And when I try to create a room from the menu, the same error message appears every time:
CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
But when I try to use OnJoinedLobby or OnConnectedToMaster, they just don't get called.
For some reason, connecting to the lobby via PhotonNetwork.JoinLobby () doesn't happen at all.
How do I create a room anyway?
Sorry for using Google translator.
Viewing all 8947 articles
Browse latest View live


Latest Images

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