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

PUN 1.93 UWP build errors

$
0
0
Hello! We cannot build our game for UWP .NET4.6 with .NET Core due to multiple errors: Placeholder path on Assets/Plugins/Photon3Unity3d.dll is wrong: "Assets/Photon/PhotonLibs/Photon3Unity3D.dll". Changed it to "Assets/Plugins/Photon3Unity3D.dll". Then following errors appear: Assets\Photon Unity Networking\Plugins\PhotonNetwork\NetworkingPeer.cs(836,55): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) Assets\Photon Unity Networking\Plugins\PhotonNetwork\PingCloudRegions.cs(198,56): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) Assets\Photon Unity Networking\Plugins\PhotonNetwork\PingCloudRegions.cs(200,24): error CS0246: The type or namespace name 'PingMono' could not be found (are you missing a using directive or an assembly reference?) I've tried to compare code to PUN 2 but cannot fix it fast. Any workarounds? P.S. Got same problems with PUN 1.94

Synchronize UI gamebject over the network

$
0
0
Hi, I have a photon voice chat demo and I want to synchronize a gameobject that is not a player (for example a Text element with variable string text). How to do that? Use PhotonView is a valid option? some step by step instruction please?

New players spawning twice on existing players

$
0
0
I have this problem when new players join the room, they get instantiated twice on all the existing players. I read the code from the PunBasics demo and tried to replicate how it works but the problem still occurs no matter what I do. I checked the logs on the new players and see that NetworkManager Start function gets called as many times as there are players and I believe this is normal Unity behavior but it should only spawn one player instance for each new player as there is a check to see if the player instance has been created already but it doesnt seem to work that way. The NetworkManager is a scene object in every scene and it doesnt have a PhotonView component. The playerPrefab gets instantiated by the NetworkManager in Start() function and that prefab has a PhotonView component. After the playerPrefab gets instantiated, it instantiates another prefab on the owner's client that is a localPlayerPrefab which then receives input from the player and plays all animations etc. Here is my code for the NetworkManager: https://pastebin.com/RzrBM8eM and here is code for the playerPrefab object that gets instantiated by the NetworkManager: https://pastebin.com/WWUdVMav I had pretty much the same setup when I was using the Unity network API and worked quite well but I cant get it to work with Photon. It might be a simple thing that I missed and just cant see.

PhotonNetworkTransformClassic - How to handle respawn of players when they "Jump"

$
0
0
In my game so far, I am simply using PhotonNetworkTransformClassic's built in observable code and so far that has worked for me. My game is a space game so the ships do not suddenly change position. Because if this, I am using: Interpolation: Estimate Speed Extrapolation Option: Estimate Speed and Turn Teleport Is Enabled and Distance is 100. Everything is smooth, as these are good options for vehicle type games (ie...object's that don't suddenly change position) However, when the player dies, that player sets its transform back to the spawn point. Usually, this triggers my Teleport setting and all is well. However, if the player dies within 100 units (< the teleport distance) of the spawn point,other players see him "slide" into the position. Whats worse, that the position is often incorrect...the player is not "On" the spawn point but off to the side. I would like to fix the slide and also the fact that the position is off. Can each client manually set the position of the object that respawned? I've always let Photon handle the position entirely, and dont know what happens if I try to manually set position at certain time. Has anyone seen this behavior and what is your strategy for fixing it? Also, I read this in the docs: Extrapolation tries to estimate where the synchronized character actually should be "now", based on previously received data. It might help avoid stuttering when updates are late or lost but is always just a guess. It might need corrections and if it works well, depends on the type of game you develop. When the docs say "it might need corrections", is that suggesting that at know points I can/should be "fixing" the position by manually setting the transform? Thanks.

Photon Premium vs Public Cloud

$
0
0
What exactly are the differences? I can see that Premium starts at a higher price point and that it auto-scales CCU limits, but what would be the difference between say Photon Public 2000 CCU and Photon Premium? Does premium allow plugins or higher QOS? Thanks, David

[Photon Classic] Issues connecting with previously working project

$
0
0
I'm having issues communicating with your servers on a project that once worked fine. Even when I use your connectandjoinrandom script. It goes fine until it needs to create a room then I get no further responses. The last message logged is: OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null); My ServerSettings are as follows: https://prnt.sc/os43a0 Please advise.

Creating players after loading

$
0
0
Hello! So I've been working on a game, and I have a problem when trying to create the players. I want the game to load a scene, and when the scene is loaded for all clients, I want to create the players. This works fine in my test world with no problems. But once I change to the main world (which is kinda big), it doesnt work. Both of the clients load the scene, but neither of them have the player created. I have tried several ways to check if the clients are ready. At the moment, I have a Coroutine, on the main client that checks the custom properties of each client to check if they are ready. And once they are, it sends the RPC_CreatePlayer. I've been struggling to get this to work for a few weeks now. I would love it if anyone has any tips, or could help me with the code to get it to work. Thanks in advance!

Photon Pun OnTriggerEnter function

$
0
0
Hello, in my script 2 players side by side i have activated a button , button name is raceButton.Function works when the 2 players come side by side, the test button is active,but the raceButton button is active in all players. I just want to be active in side-by-side players. How can I do that. This is my code:
  private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag=="Player")
        {
            Debug.Log("Araçlar yanyana");
            target = other.gameObject.transform;
            view.RPC("VeriGonder", PhotonTargets.AllBuffered, sender.gameObject.GetPhotonView().viewID, target.gameObject.GetPhotonView().viewID);
        }
    }

    [PunRPC]
    void VeriGonder(int senderView, int targetView)
    {
        sender = PhotonView.Find(senderView).transform;
        target = PhotonView.Find(targetView).transform;

        ownerId = sender.gameObject.GetPhotonView().viewID;
        playerNameText = target.GetComponent().owner.NickName;


        if(target!=null)
        {
          sender.GetComponent().raceButton.SetActive(true);
          target.GetComponent().raceButton.SetActive(true);
        }
    }

PhotonView ID Resetting

$
0
0
Hi, I'm writing about an issue my team is trying to get around regarding PhotonView IDs being modified for prefab instances at Editor time. This is not an issue at runtime off of a build, or in Editor runtime without remote clients. However, in a multiple client situation set up using multiple Unity Editor runtime instances (i.e. not running a build runtime) running on the same or multiple systems, there is a good chance that Photon Editor script logic will modify the PhotonView ID, causing different Unity Editor instances to have different view ID sets, breaking view ID syncing. We discovered that the view ID change is being caused by PhotonViewHandler.cs modifying the PhotonView ID of the prefab itself and setting it to zero. E.g. when a prefab instance override is made, a prefab instances will get the zero value and Photon Editor logic will assign it a new ID. Reproduction steps: 1. In Editor, create a prefab and attach a PhotonView component to it. 2. In Editor, create an instance of that prefab in any scene. Observe the PhotonView ID of the instance. 3. Make a modification to the prefab in the scene hierarchy view. 4. Apply the prefab instance override change to the prefab. 5. Observe the PhotonView ID after the override. It will be different. Outside of these steps, we have also observed that a PhotonView ID changes before entering runtime (in Editor) as well. We would like to understand the official purpose/effectiveness of the ID reassignment behaviour, and how it fits with the intended usage of PhotonView IDs. In case we are misusing Photon, we are looking for advice on how to get around the issue of PhotonView ID desync across client instances. So far, the only path forward is to share a consistent build version across clients when testing multiplayer behaviour, but this isn't always efficient while developing. Thus far we have tried applying the following solutions to get around this issue (we've settled on the 3rd): 1. Use version control to sync your unity project across clients. However, this is unreliable due to IDs sometimes changing on entering Play Mode. 2. Modify the Photon Code (PhotonViewHandler.cs) to make sure the prefab ID isn't modified for a prefab and that the IsPrefab check identifies the prefab correctly. However, we wish to avoid modifying plugins at all costs, for future maintenance reasons and to avoid more undesirable issues. 3. Develop a script that maintains a list of all PhotonView gameobjects in a scene during Editor mode and uses RaiseEvents during runtime to ensure that all the PhotonView IDs are synchronized across multiple clients. (See the script attached) We are moving ahead with option 3, but it feels like overkill to do this, so we'd like to check if we're approaching this problem correctly. Thanks! Ante PhotonViewIdSync script we wrote: (partial class body simplified of irrelevant bits)

public class PhotonViewIdSync : MonoBehaviour
{
    #if UNITY_EDITOR
    
    [SerializeField] private List _photonViewInScene;
    private static List PhotonViewsInScene
    {
        get => Instance._photonViewInScene;
        set => Instance._photonViewInScene = value;
    }


    #region MonoBehaviour

    private void OnEnable()
    {
        NetworkManager.AddRaiseEventListener(RaiseEventCode.PhotonViewIDSync, ReceivePhotonViewId);
    }

    private void OnDisable()
    {
        NetworkManager.RemoveRaiseEventListener(RaiseEventCode.PhotonViewIDSync, ReceivePhotonViewId);
    }

    private void Start()
    {
        StartCoroutine(SynchronizePhotonViewID(SceneManager.GetActiveScene(), LoadSceneMode.Single));
    }

    #endregion MonoBehaviour


    #region Synchronization

    private IEnumerator SynchronizePhotonViewID(Scene scene, LoadSceneMode mode)
    {
        yield return new WaitUntil(() => NetworkManager.IsReady);
        if (!PhotonNetwork.IsMasterClient) yield break;

        Debug.LogFormat(DebugLogFormat, "SynchronizePhotonViewID", " Synchronizing Photon Views in Scene " + scene.name);
        for (int i = 0; i < PhotonViewsInScene.Count; i++)
        {
            SendPhotonViewId(i, PhotonViewsInScene[i].ViewID);
        }
    }

    public static void SendPhotonViewId(int index, int viewID)
    {
        SendOptions sendOptions = new SendOptions {Reliability = true};
        object[] eventContent = new object[] {index, viewID};
        RaiseEventOptions raiseEventOptions =
            new RaiseEventOptions {CachingOption = EventCaching.AddToRoomCache, Receivers = ReceiverGroup.Others};
        PhotonNetwork.RaiseEvent(RaiseEventCode.PhotonViewIDSync, eventContent, raiseEventOptions, sendOptions);
    }

    public void ReceivePhotonViewId(EventData photonEventData)
    {
        object[] sentData = (object[])photonEventData.CustomData;
        int index = (int)sentData[0];
        if (index < PhotonViewsInScene.Count)
        {
            PhotonViewsInScene[index].ViewID = (int)sentData[1];
        }
    }

    #endregion Synchronization


    #region EditorMode

    private static EditorBuildSettingsScene[] _scenes;
    private static int _currentSceneIndex = 0;
    private static string _activeScene;

    [MenuItem("Photon/Update Photon View List %g")]
    private static void LoadViewsToList()
    {
        if (Instance == null)
        {
            Debug.LogFormat(DebugErrorFormat, " Missing Component", " Please add a PhotonViewIDSync component to any gameobject.");
            return;
        }

        _scenes = EditorBuildSettings.scenes;

        EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
        EditorSceneManager.activeSceneChangedInEditMode += AddSceneViewsToList;
        _activeScene = EditorSceneManager.GetActiveScene().path;
        EditorSceneManager.CloseScene(EditorSceneManager.GetActiveScene(), false);
        LoadNextScene();
    }

    private static void LoadNextScene(string sceneToLoad = null)
    {
        EditorSceneManager.OpenScene(sceneToLoad ?? _scenes[_currentSceneIndex].path);
    }

    private static void AddSceneViewsToList(Scene one, Scene two)
    {
        _currentSceneIndex++;

        object[] obj = FindObjectsOfType(typeof(GameObject));
        PhotonViewsInScene = new List();
        Scene currentScene = EditorSceneManager.GetActiveScene();
        foreach (object o in obj)
        {
            GameObject newGO = (GameObject)o;
            PhotonView newView = newGO.GetComponent();
            if (newView == null) continue;

            PhotonViewsInScene.Add(newView);
            Debug.LogFormat(DebugLogFormat, "AddSceneViewsToList", "Adding PhotonView " + newGO.name);
        }

        if (_currentSceneIndex < _scenes.Length)
        {
            LoadNextScene();
        }
        else
        {
            EditorSceneManager.activeSceneChangedInEditMode -= AddSceneViewsToList;
            _currentSceneIndex = 0;
            Debug.LogFormat(DebugLogFormat, "AddSceneViewsToList", " PhotonView List Updated. ");
            EditorSceneManager.SaveScene(two);
            LoadNextScene(_activeScene);
        }
    }

    #endregion EditorMode

    #endif //UNITY_EDITOR
}

Photon View with already existing object in scene

$
0
0
I couldn't find anywhere in the documentation if a GameObject that is already in the scene can be synced with others? I've also tried to add the PhotonView Component on my GameObject at runtime but it didn't work. Is it something PUN supports or I have to instantiate my GameObject in order to be synced?

PUN - Disconnects with to many Photon Views instantiated

$
0
0
Hey, So when I'm testing my game, I get disconnected after too many minions are spawned. No error or log gets debugged, the game objects associated with the player just get destroyed. I believe this is to do with having too many PhotonViews attached to objects. I'm testing all three players/instances of the game on the same PC and the other instances don't disconnect when this happens. It happens after about 30 are spawned. If relevant, this is on AU servers. Its an RTS style game, each minion on the local side has an animation controller and a NavMeshAgent, over the network I'm syncing the transform and the animation. Disabling the navmesh for remote clients. I was hoping someone could provide me with some info on the capabilities of PUN. Am I doing a bad practice? Like should I be managing the syncing differently and limiting the photon views being used. Hope someone can help :)

Master Client Disconnects When Second Player Joins

$
0
0
Hi. Sometimes when I have a single player in a room and a second player joins, the first player will disconnect. I tried finding the reason for the disconnect and the message is "DisconnectCause.DisconnectByServerReasonUnknown". The PUN logs don't seem to say why it's happening either. Usually this happens when I leave the first player in a room doing nothing for about 2-5 minutes and then have another player join which disconnects the first player. Is there some sort of AFK timer that triggers this even though the game is running (not in background)?

Increase send interval for specific PhotonView object?

$
0
0
Hi! I have a multiuser pen drawing app where the pen object's position and rotation are observed and synced around the room. However, the sync frequency is too low for it to produce proper representations of the drawings. Before I go into sending actual line data (which is what I'll probably do later), I wanted to try increase the send frequency per second on that PhotonView -- is there a way to do that? Thanks!

Get packets loss

How does the master client know others players joined room?

$
0
0
I would like others players joined room after master client will receive callback.

Issues When Adding PhotonViews to GameObjects at Runtime

$
0
0
Hello! I am working on a game where I need to be able to add and remove PhotonViews to objects at runtime relatively frequently. I have a system where I add a PhotonView on the client side, then send the name of the GameObject, and the ViewID that I allocated to the PhotonView through a custom PhotonView (lets just call it SharedInfo) script that I have created. SharedInfo then sends the data over the network to itself (serializes it? I'm not sure what the technical term is for this). It uses the name that is sent over the network to find the corrosponding GameObject and creates a PhotonView on that object, with a ViewID that is the same as the one sent over the network. Sorry if I explained this poorly. Anyways, when the master client runs this, everything works fine. But the weird thing is that when a non-master client runs this, I get the following warning. Received OnSerialization for view ID XXXX. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined What is weird is that the warning doesn't appear at all on the non-master clients. It only appears on the master client when a non-master client tries to run through this "process". What I also find strange is that it seems to be stopping SharedInfo from reading anything from the stream on the master client (as I found out by putting a debug.log in the start of if (stream.isreading), and seeing that the debug.log never showed up in the console). Again, I'm sorry if this is explained poorly. But does anybody have any ideas as to why this might be happening?

Runtime PhotonView components

$
0
0
So I have a ton of prefabs and content that is loaded from assetbundles and I wish to keep track of their state. Is it possible to add PhotonView components etc at runtime after being instantiated? If not what is a workaround for this?

How to add a PhotonView by script

$
0
0
Hi guys, I want to add a PhotonView script to my gameobject, I have tried with this.gameObject.AddComponent(); , but when I use it, it throws null. What Am I doing wrong? Thanks

Fast collisions with Photon Rigidbodys (Golf game)

$
0
0
I am working on a networked golf game and trying to add collision between the balls. Each player has a ball prefab with Photon components like so: https://imgur.com/VrP10Jc As it is right now, the balls often don't register a collision when they are moving too fast, although they register fine for slower collisions. Is there any other setting that can help me register fast collisions? An alternative is to have the master client own all the balls and simulate all the movement. However, that's not very smooth from the player's perspective because every time they hit their ball, they might have to wait 100-200 ms to see it actually move. Any ideas welcome!

Disconnected while loading large scenes

$
0
0
Hello, first post here. After upgrading my project from PUN1 to PUN2, I noticed that my smaller scenes load just fine, but my large scene which takes between 10 and 45 seconds to load results in a disconnect on slower machines about 2 seconds after the level is loaded. If the machine loads it quickly, there is no disconnection. Per the Analyzing Disconnects page, the fix for Unity users was to make sure that the PhotonNetwork.IsMessageQueueRunning = false before loading and re-enabling it after. My project already had that code built in and was working just fine on all scenes and machines before the upgrade to PUN2. In other words, that fix is not working on PUN2 for me. After these tests, I'm thinking PUN2 has a regression on this issue. Has anyone else had this problem?
Viewing all 8947 articles
Browse latest View live


Latest Images

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