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

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?

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.

PUN2 Unused Assets Cleaner Guide (Release Build)

$
0
0
Hi there!
Is there any guide what files/folders I can remove from PUN2?
For example I definitely don't need Demos folders, because I don't want files in Resources folders from Demos to be included in my release build.
Thank you!

Matchmaking: How to handle max players per TEAM (2 teams) and MMR?

$
0
0

Hi I'm having an issue with teams using pun 2 matchmaking. I can remove the number of spaces available on a particular team using room properties for each player(s) that join, but I can't find a way to make conditional searches work when looking for a game. For example, I have 3 people in my party, there's still space for 3 but 2 will be on team 1 And one will be in team 2.

I'm essentially looking for a way to say if party is larger than t1 and t2, keep searching.

Secondarily, I'd like to have a multiplayer rating. Each player would have a rating, as they join the rating is averaged so like-leveled players would be together. Is there. Way to do this in Photon?
Thank you.

Master Client RPC vs Room CAS for Node-Grid Synchronization

$
0
0
Hi everyone,

I hope the title makes sense. Essentially, I have a 3D Node grid, and I manage this locally with a Dictionary<Vector3Int, Node>. However, I've run into complications trying to keep this grid synchronized with online play, and I am looking for advice or ideas with the most optimal way to do this.

This grid can have objects placed / built onto it (it is an RTS), but there are fringe cases where two players attempt to build something in the same place at the same time. To me this sounds like the perfect CAS solution - however, my grid isn't small. I'm currently working with a 100 x 100 x 10 grid. I figured with an IsBuildable bool and an Owner int, there are 4 bytes per node .. and with 100,000 nodes that's an easy 0.4mb of meta data that would need to be constantly synchronized which doesn't sound optimal at all. It crossed my bind to break the grid down into various quadrants and control those as a matrix per hashtable key ... but that doesn't feel correct.

Alternatively, I considered using a master client RPC to control each Node in real time, and the RPC structure was similar to the room properties CAS. This came with its own complications though, and more specifically, the game would lock if the master client was having connection issues.

Maybe my assumption about the 0.4mb synchronization wouldn't be an issue .. but I'm hoping I am way out in left field with respect to the most correct solution for something like this.


Thank you,
CS

Photon Manual Instantiation PhotonView.Owner is NULL

$
0
0
Hello, I'm spawning player with this code. When I check PhotonView.Owner it gives null. Thank you. Is it bug or normal? What can I do for it? Update: Also PhotonView Owner value in inspector is" Scene" and PhotonView.IsMine is true for both player which is wrong..
public void SpawnPlayer()
{
    GameObject player = Instantiate(PlayerPrefab);
    PhotonView photonView = player.GetComponent<PhotonView>();

    if (PhotonNetwork.AllocateViewID(photonView))
    {
        object[] data = new object[]
        {
            player.transform.position, player.transform.rotation, photonView.ViewID
        };

        RaiseEventOptions raiseEventOptions = new RaiseEventOptions
        {
            Receivers = ReceiverGroup.Others,
            CachingOption = EventCaching.AddToRoomCache
        };

        SendOptions sendOptions = new SendOptions
        {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(CustomManualInstantiationEventCode, data, raiseEventOptions, sendOptions);
    }
    else
    {
        Debug.LogError("Failed to allocate a ViewId.");

        Destroy(player);
    }

private void OnEnable()
    {
        PhotonNetwork.AddCallbackTarget(this);
    }

    private void OnDisable()
    {
        PhotonNetwork.RemoveCallbackTarget(this);
    }

    public void OnEvent(EventData photonEvent)
    {
        if (photonEvent.Code == CustomManualInstantiationEventCode)
        {
            object[] data = (object[]) photonEvent.CustomData;

            GameObject car = (GameObject) Instantiate(Cars[(int)data[4]], Vector3.zero, Quaternion.identity);
            
            car.transform.GetChild(0).position = (Vector3) data[0];
            car.transform.GetChild(0).rotation = (Quaternion) data[1];

            PhotonView photonView = car.GetComponent<PhotonView>();
            photonView.ViewID = (int) data[2];
            car.transform.GetChild(0).GetComponent<PhotonView>().ViewID = (int) data[3];
        }
    }
        
}

Syncing a player with multiple parts and joints

$
0
0
Hi, I am trying to sync a player with multiple parts and joints. The problem is that the joints are not being respected by Photon when syncing. Is there a way to sync the position of every part at the same time? like taking a snapshot of all parts and sending that? Here is my current setup for each part.
d22SxQc.png
kQjeBdV.png

I thought changing to the unreliable observe option would sync them at a fixed rate, but it doesn't. I have also tried deactivating the Rigidbody view and it doesn't work either:

Here is a video of the game:
https://streamable.com/hqkvhp

Get GameObject in OnPlayerEnteredRoom()

$
0
0
I am trying to get the newest gameObject that has joined the room.

So I want to add a canvas above the character that joins. It will be a name canvas that hovers above the player.
I am trying something like:
GameObject joinedPlayer = PhotonView.Find(newPlayer.ActorNumber).gameObject;
but obviosuly not correct. Does the player variable have any view of the object I need to get a hold of?

Thanks

Here are the two main functions
public void InstantiatePlayer() {

            GameObject[] spawns = GameObject.FindGameObjectsWithTag("Spawn");
            int spawnIndex = Random.Range(0, spawns.Length);

            Debug.LogFormat("We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName);
            // we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
            GameObject MyPlayer = PhotonNetwork.Instantiate("Car"+PlayerPrefs.GetInt("playerCar"), new Vector3(spawns[spawnIndex].transform.position.x, spawns[spawnIndex].transform.position.y, spawns[spawnIndex].transform.position.z), Quaternion.identity, 0);

        }

        public override void OnPlayerEnteredRoom(Player newPlayer) {
            //Add name to car
            Debug.Log(newPlayer.ActorNumber);
            GameObject joinedPlayer = PhotonView.Find(newPlayer.ActorNumber).gameObject;
            GameObject go = Instantiate(myName, new Vector3(joinedPlayer.gameObject.transform.position.x, joinedPlayer.gameObject.transform.position.y+5.0f, joinedPlayer.gameObject.transform.position.z), Quaternion.identity) as GameObject;
            go.gameObject.transform.parent = joinedPlayer.transform;
        }

ClientTimeout when 5+ players

$
0
0
Hi there, I'm getting client timeout errors when a fifth player joins my games in photon 2.19.1. My default maxplayers is set to 5, so I thought maybe it wasn't taking that setting in properly, but when I query maxplayers it definitely shows as 10.

So the fifth player joins, and then two players are kicked from the game with a ClientTimeout error with no more details.

I can't figure out how to debug this; I would really appreciate some help. I am pretty sure I'm not doing anything wrong, but then this is first time I've tried 5+ players since I've updated to photon 2

PhotonWebSocket linking issue when building WebGL target

$
0
0
Hi all,

We updated Photon engine to the latest 2.21. Since then, we are not able to build our webgl game anymore.
Here is the error that we are seeing:
Assets\Photon\PhotonLibs\WebSocket\WebSocket.cs(5,7): error CS0246: The type or namespace name 'WebSocketSharp' could not be found (are you missing a using directive or an assembly reference

Any idea of how we can fix this?

Ben

[Suggestion] Add new RPCTarget option: ViewOwner

$
0
0
I think the title is self explanatory

Out of nowhere the room listing does not work.

$
0
0
Hello!

Everything seemed to be fine with Photon and the room listing before today.

Normally whenever I would create a room on clients it would show but that is not the case today.

I get a "Connected to Photon" debug message when starting the first instance and it is able to create a room just fine.

It isn't until I run a second instance and attempt to join the room that the first instance made that I run into trouble.

I hit my head against the wall for a bit trying to find some kind of error code because it isn't until I close the first instance that I get this error message...

Unity Console Preview
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Unity Console Extended Message
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <437ba245d8404784b9fbab9b439ac908>:0)
JoinEventMenu.OnRoomListUpdate (System.Collections.Generic.List`1[T] roomList) (at Assets/Scripts/EventMenu/JoinEventMenu.cs:56)
Photon.Realtime.LobbyCallbacksContainer.OnRoomListUpdate (System.Collections.Generic.List`1[T] roomList) (at Assets/3rdParty/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3970)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/3rdParty/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2880)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <11e9abbca912444aa80ed58a280369fc>:0)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <11e9abbca912444aa80ed58a280369fc>:0)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <11e9abbca912444aa80ed58a280369fc>:0)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/3rdParty/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/3rdParty/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

I am so confused.

Connecting to Self Hosted NameServer

$
0
0
How can I connect to a name server on self-hosted from PUN?

Connecting to a master server is easy as the API is exposed as
PhotonNetwork.ConnectToMaster()
so I can provide my own IP address etc.

However there is no option to do this for the name server. I tried tinkering with
PhotonNetwork.ConnectUsingSettings()
using an AppSettings object, but that didn't work.

Edit: of course I am using self-hosted v5, as v4 doesn't have the NameServer application.

Local player input on multiplayer game

$
0
0
Hi, I am fairly new to Photon and currently work on a multiplayer game it. I wonder if there is a possibility to determine whether the input was made from the local player even if the script that takes the input is not on the player gameobject instance. So for player movement I check in a PlayerScript via
if(photonView.IsMine)
if the local player made the input, so that each player can only control their own player instance.

Now there are several obstacles in the scene that every player should have the possibility to interact with. Eeach requires unique and specific user input so the scripts which take and process the input are on the objects themselves. These objects do have photonViews. However, checking
if(photonView.IsMine)
is not possible here since the objects are not part of the players.

Is there a way to check on non-player objects and scripts, if the input was made from the local player?

Can't send CustomRoomProperties information.

$
0
0
I want to be able to display what gametype the lobby is currently playing and the best way to do that seems to be with custom properties.

To start, I want the room state to be 'In Lobby' so in the room creation I create a hashtable containing this information and add it to the RoomOptions like so:
using Hashtable = ExitGames.Client.Photon.Hashtable;

// Assign the room settings to a roomOptions object.
RoomOptions roomOptions = new RoomOptions
{
    IsVisible = !privateGameToggle.isOn,
    MaxPlayers = maxPlayers,
    IsOpen = true,
    CustomRoomProperties = customRoomProperties
};

// Create the room (passing in the rooms name as well as the roomOptions object).
PhotonNetwork.CreateRoom(roomNameInputField.text, roomOptions);

This all works fine, however when I try and get the custom room properties I get nothing (all the other information is received fine).
public void Setup (RoomInfo info)
{
   // Game state
   gameState.text = (string)info.CustomProperties[LOBBY_STATE_KEY];
}

Thanks,
Wzd.

Looking for some Project Advice

$
0
0
Hello,

I am new to Photon and am trying to use it to give multiplayer functionality to a board game that I am prototyping.

I am currently seeing some unexpected behaviors in my program and was hoping that someone might be able to give me a nudge in a better direction to get the kind of behavior that I am expecting.

Currently, I am using the same script to click on and to move the pieces in my game.

I am using another script to tell my pieces to ignore that script if the piece is not local to the current player:

photonView = GetComponent<PhotonView>();
if (!photonView.IsMine)
{
foreach (var script in scriptsToIgnore)
{
script.enabled = false;
}
}


The plan was going to be after the piece belonging to the local player (photonView.IsMine == true) moved, I was hoping to use the Photon Transform View component to make sure that the pieces on the other machines would move to match the local player.

Instead, I got what is displayed in the attached video…

As shown in the video, any player can move any piece, but if a player moved pieces that were spawned into existence by a local instance of the game (photonView.IsMine == true), then the IsMine == false piece instances would move into the correct positions on the other instances of the game.

I may be describing it poorly, but that is why I attached a link to the video below.

https://youtu.be/G6N8b21I8Qg

So I have two questions.

First, what might be a better way to set up my pieces so that players who do not have ownership of the pieces are not able to move them..?

And secondly, In my original program, where all of the pieces were moved by players from the same terminal taking turns “round robin” style, the pieces just teleport from one position to another using the line below...

(_movementPiece.transform.position = _movementTarget.transform.position;)

In my original code and in the instance of the program where the photonView.IsMine = true, the pieces still teleport. On other instances of the program running in the same room however, the pieces slide across the board. Again, this can be seen clearly in the attached video.

Is there any reason for this..?

Is there a way to get them to teleport as in the original version of the code..?

I ask because when they slide, if they collide with another piece while sliding across the board, they delete the piece they run into, which is not the intended action. (Well... It IS the intended action, but I was not intending for the pieces to slide across the board...)

I can probably code a fix around it just by having the pieces rise up off of the board, move into position, then come back down… But if there is another way around doing that or if I could understand why the IsMine=false pieces are sliding, that might be helpful to me also.

Thank you all for any insight you may be able to give me into these behaviors as well as any feedback you may be able to give in to anything else you may see that I could be doing better.

I am using the free version of PUN2 for Unity if that helps at all.

Is there an official/unofficial Photon Discord server around?

$
0
0
I'd love to join it~ EDIT: Made an unofficial Photon one >> https://discord.gg/uxaRmVq

Send an event to all rooms from lobby

$
0
0
Hi,
I want to be able to trigger an action from the lobby to all rooms but I don't know how to di it.

I tried to make it using a workaround: customproperties. That way I can list all rooms in the lobby and "see" the custom properties on each room and if they change, but It seems I can't change any custom property from the lobby (it's only readonly) to be able to detect that change "inside" the room (that way I could trigger an action from inside the room when the change in the custom properties are detected)

Is there any kind of "event" or "signal" that can be sent to all rooms (some sort of general RPC).

The point of all this is to start an event (fire some music and animations) in all multiplayer rooms at an specific time. I want to do it from lobby and monitor if all works fine by looking at the changes in customproperties I can make from inside the room (for example, in case something goes wrong I just can change a specific custom property and detect it for "outside" in the lobby just listing all rooms and its properties).

Any idea?

StartFallbackSendAckThread() not working properly on Android X

$
0
0
I'm using Photon PUN (newest version) with On-Premise (V4 lastest) Photon Server. When my application change state to paused, the PUN called method StartFallbackSendAckThread() and this method will try to start one thread to keep pinging to server to avoid timeout disconnect after period of time
I have tested on Android X thread is running, server still received ping packet but client still got timeout disconnect, and server log peer is timed out disconnect too.
But it doesnt happen on Android 9 or lower.
Did anyone tested it ?

Developing card game, some questions

$
0
0

I'm working on card game. I want to implement mechanic like f.e. in Hearthstone where u can steal card from opponent deck. Please tell me is my way of approach is correct.
For now I store players deck as List. So when game starts clients are not aware of other client deck. I want to pass that information as hidden as I can to prevent any cheating. Below my ideas.
1. Spawn all cards at runtime, list them and shuffle. Now when I call RPC to shuffle that list are the orders on all clients will be the same? After shuffle I want to tag each one with different tag and send to other client only tags of current deck but will them be the same on both clients?
2. What with RNG. If I call Random.Range in RPC would number be the same on both clients? Instead of Shuffle I could generate number which will be index of list, assign tag and remove if from list but again is it the same number on both?
Or am I completely wrong and there is good way to do that.

I try to avoid passing Game Object names because I think it would be too easy to access.

Viewing all 8947 articles
Browse latest View live


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