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

[Question] Photon Rigidbody Collision Problem

$
0
0
crossposted: https://www.reddit.com/r/Unity3D/comments/85r5tz/photon_rigidbody_collision_problem/ I've wasted several hours trying to figure this out and really need some help... I'm working on a golf game that has a collision system that works great locally, but not when networked. Each player controls a ball (with a sphere collider and rigidbody), which moves over mesh colliders (in most cases I'm not able to substitute primitive colliders). The balls have both PhotonTransformViews and PhotonRigidBodyViews. Photon Transform View: Synchronize Position: Enable teleport = yes | Teleport if distance greater than = 0.9 | Interp option = Lerp | Lerp speed = 1.5 | Extrapolate option = Disabled | Draw sync position error = yes Synchronize Rotation: Interpolation Option = Lerp | Speed = 1.5 PhotonRigidbodyView: Sync velocity = yes | Sync ang velocity = yes Ball rigidbody: Interpolate: None | Collision Detection: Continuous Dynamic Say Player A and Player B are playing a game. Player A, from his perspective, behaves normally. Yet Player B's perspective of Player A is wrong. The rigidbody clips through the mesh colliders on the floor. It is a hard to reproduce bug. It may be because the PhotonRigidbodyView doesn't perform correct Continuous collisions. I suppose one option I have is to try all physics on the master client (server).

back to Master

$
0
0
For several reasons, I should go back to Master for matchmaking even after users joined in lobby and room. I think that PhotonNetwork.Reconnect() is the solution.. but it worked at once.. Can you show me the way to find go back to Master..!

Sync two players in VR

$
0
0
Hey guys, For my university project I have a setup of two HTC Vives and I use SteamVR, Photon Pun 2 and the VRTK plugin from Github. I followed the Photon Pun 2 Basic Tutorial successfully including step 4. What I want to achieve now is to have two players in one scene. Therefore I tried instantiating the player. What I got so far is the first player who can see and move his own controllers and the second player who sees the controllers of both player but only moves the ones from the first player. You can see the project on Github. Any help or ideas would be very much appreciated since I struggle with this problem for over a week now.

One of my steam friends seem to connect but cant join/see any servers.

$
0
0
I've tried setting the server to just NA but maybe i messed something up? For context I live in NA and he lives down the street from me so i don't think its that. He does have a VAC game ban 4 years ago but i never set up filtering VAC bans. So far 6 other people have tried to make/join lobbys and have no issues. He just seems to be on his own "server". I have an overlay set to disappear when connected to master so i know his is connecting at least. Any tips?

How do I send RPC call right before I disconnect from the server? (or leave the room)

$
0
0
Hi, thanks for taking interest in my question. So basically, I am making a multiplayer VR game and I have run into a problem. When I grab an object, I take ownership of it and send RPC call to everyone that now this object is grabbed and do other stuff, like disable gravity. I noticed that if I am holding an object and I leave the game (stop Unity editor play mode), Both my virtual player and the grabbed object disappear. What I would like to do is to Release any objects that I am holding before disconnecting. What I tried to do was to set OnDestroy method on my root VR character script that should release any objects being held (the object itself is responsible for RPC calls, like GetGrabbedRPC and GetReleasedRPC). This doesn't work because I get disconnected before OnDestroy is called. The other thing I tried was to get my VR character tagged upon instantiation (OnPhotonInstantiate). And when OnPlayerLeftRoom, I would get the tagged object and use it to release any held items and then destroy itself, but I probably don't have enough knowledge for that, because what happens is that RPC doesn't get fired and the VR character doesn't even destroy itself, rather it becomes IsMine object of another active player. Any help would be appreciated, I hope you guys understood what the problem is. Let me know if I can provide any useful information!

Unable to get two iPads to join the same room.

$
0
0
I am using the join or create room method. When I try on two ipads, they always create their own rooms instead of connecting to each other.

But, I am able to connect two iPhones or Connect an iPhone to a iPad.

Are there special settings?

Change other player custom properties with c++

$
0
0
How do I get a MutablePlayer from the Room ,from another player that is not the local player ?

Tutorial section 5 - Object reference not set to an instance of an object

$
0
0
Hi all, I am currently working on section 5 of the PUN basics tutorial (https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-prefab), and everything went rather smooth up until now. In this section, you are asked to create a PlayerManager script and attach it to your My Robot Kyle prefab. My code is as follows, and please see a screenshot of my UI as well (showing My Robot Kyle prefab, that it is in the Resources folder, etc.). The error I get is: "NullReferenceException: Object reference not set to an instance of an object Com.MyCompany.MyGame.PlayerManager.Update () (at Assets/Scripts/PlayerManager.cs:55)" Could you please help me out?
using UnityEngine;
using UnityEngine.EventSystems;
using Photon.Pun;

using System.Collections;

namespace Com.MyCompany.MyGame
{
    /// 
    /// Player manager.
    /// Handles fire Input and Beams.
    /// 
    public class PlayerManager : MonoBehaviourPunCallbacks
    {
        #region Private Fields

        [Tooltip("The Beams GameObject to control")]
        [SerializeField]
        private GameObject beams;
        //True, when the user is firing
        bool IsFiring;
        #endregion

        #region Public Fields

        [Tooltip("The current Health of our player")]
        public float Health = 1f;

        #endregion

        #region MonoBehaviour CallBacks

        /// 
        /// MonoBehaviour method called on GameObject by Unity during early initialization phase.
        /// 
        void Awake()
        {
            if (beams == null)
            {
                Debug.LogError("Missing Beams Reference.", this);
            }
            else
            {
                beams.SetActive(false);
            }
        }

        /// 
        /// MonoBehaviour method called on GameObject by Unity on every frame.
        /// 
        void Update()
        {

            // we only process Inputs if we are the local player
            if (photonView.IsMine)
            {
                ProcessInputs();
            }

            // trigger Beams active state
            if (beams != null && IsFiring != beams.activeSelf)
            {
                beams.SetActive(IsFiring);
            }
        }

        /// 
        /// MonoBehaviour method called when the Collider 'other' enters the trigger.
        /// Affect Health of the Player if the collider is a beam
        /// Note: when jumping and firing at the same, you'll find that the player's own beam intersects with itself
        /// One could move the collider further away to prevent this or check if the beam belongs to the player.
        /// 
        void OnTriggerEnter(Collider other)
        {
            if (!photonView.IsMine)
            {
                return;
            }
            // We are only interested in Beamers
            // we should be using tags but for the sake of distribution, let's simply check by name.
            if (!other.name.Contains("Beam"))
            {
                return;
            }
            Health -= 0.1f;
        }
        /// 
        /// MonoBehaviour method called once per frame for every Collider 'other' that is touching the trigger.
        /// We're going to affect health while the beams are touching the player
        /// 
        /// Other.
        void OnTriggerStay(Collider other)
        {
            // we dont' do anything if we are not the local player.
            if (!photonView.IsMine)
            {
                return;
            }
            // We are only interested in Beamers
            // we should be using tags but for the sake of distribution, let's simply check by name.
            if (!other.name.Contains("Beam"))
            {
                return;
            }
            // we slowly affect health when beam is constantly hitting us, so player has to move to prevent death.
            Health -= 0.1f * Time.deltaTime;
        }

        #endregion

        #region Custom

        /// 
        /// Processes the inputs. Maintain a flag representing when the user is pressing Fire.
        /// 
        void ProcessInputs()
        {
            if (Input.GetButtonDown("Fire1"))
            {
                if (!IsFiring)
                {
                    IsFiring = true;
                }
            }
            if (Input.GetButtonUp("Fire1"))
            {
                if (IsFiring)
                {
                    IsFiring = false;
                }
            }
        }

        #endregion
    }
}

Unexpected Raise reception on PUN 2

$
0
0
Hello I changed from PUN Classic to PUN2. Then, every time an object on another terminal with PhotonView & PhotonTransformView moves, a Raise reception event is generated. EventData.Code that occurs is "201" "206". Display of console when OnChangePosition () is executed on another terminal.→ Riase Receive:2 default:201 Riase Receive:2 default:201 Riase Receive:2 default:206 Is this Raise reception a specification or is my setting incorrect? Thank you for reading!
 
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;

public class PUN2_Test : MonoBehaviourPunCallbacks
{

    //MyObject
    private GameObject myObje = null;

    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
    }
     
    public override void OnConnectedToMaster()
    {
        PhotonNetwork.JoinOrCreateRoom("room", new RoomOptions(), TypedLobby.Default);
    }

    public override void OnJoinedRoom()
    {
      myObje=  PhotonNetwork.Instantiate("GamePlayer", new Vector3(0,0,0), Quaternion.identity);
    }


    //Button Event
    public void OnChangePosition()
    {
        var v = new Vector3(Random.Range(-10f, 10f), Random.Range(-3f, 3f));
        myObje.transform.position = v;
    }

  
  
public class MyRaise : MonoBehaviour
{   
    private enum EEvent : byte
    {
        event1 = 1
    }

    private void OnEnable()
    {
        PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
    }

    private void OnDisable()
    {
        PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
    }         

    //Send.Button Event
    public void StartRaise()
    {
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All };
        SendOptions sendOptions = new SendOptions { Reliability = true };
        PhotonNetwork.RaiseEvent((byte)EEvent.event1, "hogehoge", raiseEventOptions, sendOptions);
    }

    //Receive
    public void OnEvent(EventData photonEvent)
    {
        Debug.Log("Raise Receive:"+ photonEvent.Sender.ToString());

        switch ((EEvent)photonEvent.Code)
        {
            case EEvent.event1: Debug.Log("event1  Receive:"+(string)photonEvent.CustomData); break;
            default: Debug.Log("default:" + photonEvent.Code); break;
        }
    }
       
}
  
Unity 2019.1.12f1 PUN2 version 2.13

PhotonNetwork.Instantiate question

$
0
0
Was wondering why when I call PhotonNetwork.Instantiate and create the root playerGO on host in editor, it creates 2 gameobjects with appropriate IDs, but when I host off a client, it only creates one gameobject for my editor.

Duplicate OnRoomListUpdate Callback.

$
0
0
Hey, thanks in advance for any help. The current issue I'm facing is when I leave a room, OnRoomListUpdate() gets called twice. The first call lists rooms correctly, the second one adds a room back with 0 players. Through logs and debug I see that when I leave a room, I reconnect to master. Then the OnRoomListUpdate callback occurs. Then 1 second after calls again with an empty room. To leave the room I am calling LeaveRoom(false), as to abandon. And played with room options like CleanupCacheOnLeave, EmptyRoomTtl, and PlayerTtl. No luck. For now, I will just have a check on the room button prefab to self destruct if the player's count is 0. My intention is to never have an empty room in the list. Cheers :smile:

VR Multiplayer

$
0
0
Hello all, can anyone explain to me how to make multiplayer games. I'm kinda stuck somewhere in the middle in developing multiplayer games. or maybe there is a link for me to refer to make multiplayer games which can play in VR Thank you !

OnRoomListUpdate gets called only when joining lobby and is always empty

$
0
0
There is a lot of discussions around this particular callback but none seems to answer my problem. I tried using this callback to get the list of rooms available so I can choose which one I want but it doesnt seem to work. I get the callback when I join the default Lobby but list count is always 0, even when I start another instance before. Also, it is never called again even if I create a room on another computer. Here is the code: https://pastebin.com/AATYCcfY

Room list returns count of 0

$
0
0
Hi! My goal is to get a room list with a second LoadBalancingClient while already in a room. I'm using PUN2 and latest Unity. After creating a public and with lobby-exposed-properties room like this (and giving it many seconds to exist, so no racing)...
Hashtable properties = new Hashtable();
properties.Add(RoomProperty.Name.ToString(), "Welcome Island X");
properties.Add(RoomProperty.Scene.ToString(), Scene.Island);
        
string[] lobbyExposedProperties = new string[]
{
    RoomProperty.Name.ToString(),
    RoomProperty.Scene.ToString(),
};
        
RoomOptions options = new RoomOptions();
options.MaxPlayers = (byte) 8;
options.IsVisible = true;
options.IsOpen = true;
        
options.CustomRoomProperties = properties;
options.CustomRoomPropertiesForLobby = lobbyExposedProperties;
        
PhotonNetwork.CreateRoom(null, options);
... and then creating the secondary LoadBalancingClient like this (note I'm restricting to "us" in all region settings, also in the dashboard and PUN highlight settings) ...
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;

public class PhotonRoomPoller : MonoBehaviourPunCallbacks, ILobbyCallbacks
{
    Action callback = null;
    LoadBalancingClient client = null;

    public void GetRoomsInfo(Action callback)
    {
        this.callback = callback;
        
        Debug.Log("Starting LoadBalancingClient...");
        client = new LoadBalancingClient(PhotonNetwork.NetworkingClient.ExpectedProtocol);
        client.AddCallbackTarget(this);
        client.StateChanged += OnStateChanged;
        client.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
        client.EnableLobbyStatistics = true;
        client.ConnectToRegionMaster("us");

        // if (callback != null) { callback("Hello World"); }
    }

    void Update()
    {
        if (client != null)
        {
            client.Service();
        }
    }

    void OnStateChanged(ClientState previousState, ClientState state)
    {
        switch (state)
        {
            case ClientState.ConnectedToMaster:
                Debug.Log("*** ConnectedToMaster");
                client.OpJoinLobby(null);
                break;
                
            case ClientState.JoinedLobby:
                Debug.Log("*** JoinedLobby");
                break;
        }
    }
    
    public override void OnRoomListUpdate(List infos)
    {
        Debug.Log("*** OnRoomListUpdate");
        Debug.Log("Room count: " + infos.Count); // XXX
        foreach (RoomInfo info in infos)
        {
            Debug.Log(info);
        }
    }

}
... I'm getting a rooms count of 0 where it says XXX, even though the proper order of ConnectedToMaster - JoinedLobby is called before, and InLobby is true at the time of checking. What to do? Thanks!

"Connection failure : ExceptionOnConnection " is photon server is down ?

$
0
0
is photon server by any chance is down ? for some reason since yesterday I cannot connect to the photon server I debugged the disconnect cause and it gives me a ExceptionOnConnection and according to the documents this means that either the server could be down or not running or the client has no network or a misconfigured DNS I contacted photon support and the assured me that nothing wrong from their side I tried almost everything I created a new project imported pun classic and created a new app id with a new account and tested the demo which comes with the photon package and it gives me the same error I tried to run some old multiplayer projects which use photon and used to work but no luck same doesn't connect I even tried to run a test connection on android to make sure that it has nothing to do with windows I tried to setup the port manually and although I usually let photon choose the best region I tried fixed regions (us,eu,au) and I changed the protocol to tcp but nothing works has anyone encountered this error before ? or got a solution . P.S. I am using unity

State Buffer - Interpolation/Extrapolation, Smoothing

$
0
0
Hi, I just tried to use a State Buffer to get a better Synchronization. As references i used https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking http://wiki.unity3d.com/index.php/NetworkView_Position_Sync and some other old Forum posts. The Technique works good so far but i got some kind of jitter. After Implementing Extrapolation, i figured out it switch between Interpolation and Extrapolation quite often.Even if it does not, there is no smooth Movement. My code: https://pastebin.com/VeiAQ8ft I would be very Interested in some Optimization, hints, tips..

Camera Networking

$
0
0
I'm creating a turn-based multiplayer game (two players) and I'm having trouble with figuring out how to handle the camera networking. When it's Player 1's turn, I want the camera for both players to follow Player 1 and when it's Player 2's turn I want both cameras to follow player 2. I've tried using TagObject to have the local camera follow the enemy player, which worked besides the rotation of the camera, because it depended on the TagObjects child object. I'm now currently trying to work with only one camera (that doesn't network UI so each player see's their own UI) that follows the player that has the active turn. However, the movement on the non-local player isn't being networked (even with adding a Photon View and Photon Transform View to the camera). I guess the main point of my discussion is to ask the best way to tackle this solution. Yes, I've gone through the Photon camera tutorial but it wasn't any help. Thank you!

Can't Reconnect when Disconnected via ServerTimeout

$
0
0
PUN 2.10, Photon Cloud, Region us I'm trying to silently reconnect users when they are disconnected, whether in a lobby, or in a room. In my current test, I have a Host device, and a Guest device.. The Host creates and joins the room. The guest joins the room. I pause the guest's unity editor until the guest drops from the Host's room, then I unpause the unity editor. No matter what I call from the guest machine, ConnectUsingSettings(), Reconnect, or RecconnectAndJoin(),, or RejoinRoom, nothing is working. The sequence of events after I unpause is as follows: OnDisconnect is fired with ServerTimeout (Disconnected GameServer) OnLeaveRoom then fires (Disconnected GameServer) Then my Network Objects are destroyed (2 players), one after the other Generally, when I call something, it will immediately fire OnDisconnected with cause of None Then I usually get the following error: Operation Authenticate (230) not called because client is not connected or not ready yet, client state: Disconnected Is there a chart that can tell me what to call based on what state and disconnect cause? Seems like this shouldn't be this difficult, or a reconnect recovery tool (small class should already be available for this, which is what I'm trying to write). Thanks in advance.

pun 2 automatically disconnected in android device

$
0
0
hello, i am facing this issue when demo app run on android device.It works fine in another device and also in editor but not on my device Connect() to 'ns.exitgames.com' (InterNetworkV6) failed: System.Net.Sockets.SocketException (0x80004005): Network is unreachable.

Plugin Network For PUN

$
0
0
hello I wrote a small extension / simplification for photon pun I will try to expand it a little bit over time, I hope someone will find it useful Code C# https://gist.github.com/NoriteSC/95478f0b92d61ed4a70c40b357d5d6b7 How use Network.Get.(IsConnectedAndIsMine/LagTime/Instantiate/Destroy/IsOffline) example code;
public Rigidbody RB;
public  Animator Anima;
private PhotonView View;
void Start(){
    View = GetComponent();
    if (IsConnectedAndIsMine(View, true)) {
        RB = GetComponent();
        Anima = GetComponent();
    }
}
void Update(){
        if(RB != null && Network.IsOffline()){
            RB.AddForce(transform.up * 1, ForceMode.VelocityChange);
        }
}
Viewing all 8947 articles
Browse latest View live


Latest Images