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

Streaming video/frames with rpc

$
0
0
Can someone maybe help me out on debugging what might be wrong with my streaming code. So short summary, I have an phone app that controls playing/pausing/stopping videos on multiple oculus go devices that connect through a pin code (room name). You can select an oculus go to watch (or are defaulted to the only one if only 1 is connected) and it will stream the image to the phone through photon. It works fine on windows and it used to work fine from android to android too, but now it only appears to work when I run my app on the OculusGo and run the phone app on the computer in the Unity editor. So in my experience while testing: windows(oculus) to windows(phone) = works oculus to windows (phone) = works oculus to android phone = doesn't work (used to work) windows (oculus) to android phone = doesn't work (used to work) https://drive.google.com/uc?id=1UdqI3NX5oUO7FkLnmlCtpBK3hZ410wS8 As you can see from the screenshot I debug all my values and have taken precautions that my frames being sent are very small, but for some reason the phone doesn't seem to receive anything at all. There is nothing interesting to see in logcat either. Real time capture script placed on OculusGo center eye camera.

[RequireComponent(typeof(Camera))]
public class RealtimeCapture : SingletonBehaviour {

    VideoController videoController;

    [HideInInspector]
    public VideoPlayer videoPlayer;

    public Text targetFPSText;
    public Text imageQualityText;

    public float targetFPS = 6;
    [Range(0,100)]
    public int imageQuality = 25;
    private bool reading = false;

    private Camera camera;

    private void Start() {
        camera = GetComponent();
        camera.forceIntoRenderTexture = true;
        videoController = VideoController.instance;
        updateValues();
    }

    private void OnEnable() {
        RenderPipeline.beginFrameRendering += RenderPipeline_beginFrameRendering;
    }

    /// 
    /// Unbind begin frame rendering on disable
    /// 
    private void OnDisable() {
        RenderPipeline.beginFrameRendering -= RenderPipeline_beginFrameRendering;
    }

    /// 
    /// Call on post render
    /// 
    /// 
    private void RenderPipeline_beginFrameRendering(Camera[] obj) {
        OnPostRender();
    }

    /// 
    /// https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnPostRender.html
    /// 
    public void OnPostRender() {
        bool canReadFrame = VideoController.instance.realTimeCaptureEnabled && PhotonNetwork.IsConnectedAndReady && !reading;
        if (canReadFrame) StartCoroutine(readFrame());
    }

    /// 
    /// Read a frame after rendering it, encode it and send it to the master client via RPC
    /// 
    /// 
    public IEnumerator readFrame() {
        reading = true;  
        if (videoController.centerEyeCamera.targetTexture != null) {            

            Texture2D texture = new Texture2D(videoController.centerEyeCamera.targetTexture.width, videoController.centerEyeCamera.targetTexture.height, TextureFormat.ARGB32, false);
            texture.ReadPixels(new Rect(0, 0, camera.activeTexture.width, camera.activeTexture.height), 0,0);

            byte[] jpg = texture.EncodeToJPG(imageQuality);
            //Debug.Log(jpg.Length/1024 + "KB");

            //Send the frame/jpg as byte array
            videoController.photonView.RPC("updateRealTimeTexture", RpcTarget.MasterClient, jpg, videoPlayer.frame);
        }

        //The FPS cannot go much higher than is currently is
        //probably won't work with much higher values >10
        yield return new WaitForSeconds(1/targetFPS);
        reading = false;
    }
}
Two functions from the VideoController:

private void renderFrameToRT(RealTimeFrame realTimeFrame = null) {        
        RealTimeFrame frameData = realTimeFrame;
        if (frameData != null) {
            if (!realTimeRenderTexture.IsCreated()) realTimeRenderTexture.Create();

            try {
                Texture2D texture = new Texture2D(realTimeRenderTexture.width, realTimeRenderTexture.height, TextureFormat.ARGB32, false);
                texture.LoadImage(frameData.jpgData, false);
                texture.Apply();
                realTimeVideoTexture.texture = texture;

                if(Debug.isDebugBuild) {
                    //Set debug info
                    frameReceived++;
                    lastFrameSizeInKB = frameData.jpgData.Length / 1024;
                }

            } catch (Exception e) {              
                if(Debug.isDebugBuild) Debug.LogError(e.Message);
            }
        }
    }

    [PunRPC]
    private void updateRealTimeTexture(byte[] bytes, long currentFrame) {
        if(realTimeCaptureEnabled) {
            renderFrameToRT(new RealTimeFrame { frame = currentFrame, jpgData = bytes, });
            PhotonNetwork.CleanRpcBufferIfMine(photonView);
        }
    }

Syncing Network-Instantiated GO only if players are on the same scene?

$
0
0
Hi! I'm working on a project that utilizes PUN, and so far it's been going great! Currently, as my way of networking works right now, players upon opening the game automatically join a room, and can only enter an "Arena" when a "Server" exists, which is just a player that "hosts" the game. Which comes to the question! I want to have all players connected to the same room (because I want RPCs to be called at any time), but I only want to sync (through the PhotonViews) network-instantiated objects only if players are in the same Scene. Is there a way around this? As of right now, players in the Main Menu will see objects spawning in their view (simply because it uses the same coordinates, or at least similar). Thank you in advance to anyone with a solution!

PUN Robot Kyle Demo Issues

$
0
0
Newbie issue - the demo doesn't seem to be working in that the photon view components aren't syncing. I've gone through the entire introduction and tutorial. Creating and joining rooms worked well and network player gets instantiated but no movement is sent or received. I've then tried using the included demo scenes but still no luck. I'm working on Unity 2019.1 LWRP so the rendering so please excuse the eye-popping materials. The left is the executable (player 2), on the right is the master. Both looking at the same corner of the room. Screenshot-2019-05-23-at-8-55-22-AM

Problem with PUN and LWRP

$
0
0
When I switched my settings on LWRP, PUN is not synchronizing my VR avatars.

[UNITY PUN2] Sending network data when Time.timeScale is at zero

$
0
0
In my game, when the round ends, I set Unity's timeScale to 0 to freeze the background and overlay a UI. When the master client, presses continue I use PhotonNetwork.LoadLevel. However, this level change is never communicated to the other clients. I've tried using RaiseEvent to tell the clients to reset their timescale back to 1 and I've tried using RPCs. Is there any way to send network data while Time.timeScale is zero? Thanks in advance!

Pun2 working in android mode debug. but not working mode production

$
0
0
When I work photon test mode works without problems, but when I generate the apk and install it it generates the following error: https://drive.google.com/file/d/1LEhemHSI-7QQQrqxJO_cdGniSWxiU5uX/view?usp=sharing apparently says that class 'photon.pun' does not exist

photonview null reference exception

$
0
0
Hi there. I'm trying to go through the tutorials, using the update that just dropped, and I'm getting a null reference exception when trying to check if(photonView.IsMine). I assumed I made a typo or something, so tried using the included PlayerManager.cs file instead, same error on awake, line 67. I was trying to maybe use PhotonNetwork.GetPhotonView() to assign it a value, but I can't because it's read only, and I don't know which view to get anyway. Halp?

how to use the countdowntimer.cs?

$
0
0
hi! is there an example on how to use the countdown timer script that is included in PUN2? I am thinking of using it to make sure all clients have the proper countdown so the game starts together ontime. thanks

Can CustomRoom Properties be retrieve by Player Instances?

$
0
0
Hello, I have a playmaker setup that has the GameManager FSM setting a Custom Room Property. Then I have the instantiated player with another FSM that tries to Get this Custom Room Property but it stay at zero value. Is this possible? What could I be doing wrong with a simple setting and getting action? This may be a question for @jeanfabre Thanks, jrDev

The game has been frozen for 10-15 seconds after resume

$
0
0
I have a problem that after the client sees the ad for about 30 seconds and returns to the game. I had the problem of missed events being sent sequentially to the client and often the game froze for 10-15 seconds. How to resume the photon can receive the fastest events and does not freeze the game. Please help me.

How to continue a chess like turn based game once internet connection is disconnected and connected

$
0
0
I have implemented photon's Pun Solution for multiplayer in my Unity3d game and it is working fine except when I intentionally turn off my phone's data for few seconds and then turn it back on, the Player game object with PhotonView that I instantiated over the network destroys. Now I want a functionality where I can reconnect my player once internet connection is restored. I am aware that using PhotonNetwork.ReconnectAndRejoin() connects the client to server back to server and then using PhotonNetwork.JoinRoom(LobbyController.RoomName) I can get connected back to the previous room. But the issue is how am I suppose to handle the player prefabs which were instantiated over the Photon network if I locally instantiate them then PhotonView has 0 as Id. Do I need to instantiate the Prefabs over the network again once internet connection is back? Please correct me if I misunderstood some functionality. For checking internet I am using recursion, once internet is restored I reconnect and rejoin the room, I cached the room name.
public void CheckIfInternetIsBackOn()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
Invoke("CheckIfInternetIsBackOn", 1);
else
{
print("Reconnecting and rejoining");
PhotonNetwork.ReconnectAndRejoin();
PhotonNetwork.JoinRoom(LobbyController.RoomName);
}
}

Continuing game once internet is disconnected and connected back again

$
0
0
I have implemented photon's Pun Solution for multiplayer in my Unity3d game and it is working fine except when I intentionally turn off my phone's data for few seconds and then turn it back on, the Player game object with PhotonView that I instantiated over the network destroys. Now I want a functionality where I can reconnect my player once internet connection is restored. I am aware that using PhotonNetwork.ReconnectAndRejoin() connects the client to server back to server and then using PhotonNetwork.JoinRoom(LobbyController.RoomName) I can get connected back to the previous room. But the issue is how am I suppose to handle the player prefabs which were instantiated over the Photon network if I locally instantiate them then PhotonView has 0 as Id. Do I need to instantiate the Prefabs over the network again once internet connection is back? Please correct me if I misunderstood some functionality. For checking internet I am using recursion, once internet is restored I reconnect and rejoin the room, I cached the room name.
public void CheckIfInternetIsBackOn()
{
    if (Application.internetReachability == NetworkReachability.NotReachable)
        Invoke("CheckIfInternetIsBackOn", 1);
    else
    {
        print("Reconnecting and rejoining");
        PhotonNetwork.ReconnectAndRejoin();
        PhotonNetwork.JoinRoom(LobbyController.RoomName);
    }
}

Can't connect (clientTimeout)

$
0
0
I'm sure there's something ridiculously simple that I'm missing which I'm going to beat myself over afterwards, but I can't for the life of me figure out why I can't connect to Photon Cloud on my game. I get the clientTimeout DisconnectCause from the OnDisconnected callback. The demo provided with the PUN 2 unity package doesn't get this error. However, if I do that same on a new project, neither the demo or my game can connect. Both get the clientTimeout warning. Here's my code:
public void Connect()
    {
        Debug.Log("Connecting...");
        // keep track of the will to join a room, because when we come back from the game we will get a callback that we are connected, 
        // so we need to know what to do then
        isConnecting = true;
        // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
        if (PhotonNetwork.IsConnected)
        {
            // #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one.
            PhotonNetwork.JoinRandomRoom();
            
        }
        else
        {
            // #Critical, we must first and foremost connect to Photon Online Server.
            PhotonNetwork.GameVersion = gameVersion;
            PhotonNetwork.ConnectUsingSettings();
        }
    }

    

    public override void OnConnectedToMaster()
    {
        Debug.Log("Connected to " + PhotonNetwork.CloudRegion);
        
        
        // we don't want to do anything if we are not attempting to join a room. 
        // this case where isConnecting is false is typically when you lost or quit the game, when this level is loaded, OnConnectedToMaster will be called, in that case
        // we don't want to do anything.
        if (isConnecting)
        {
            // #Critical: The first we try to do is to join a potential existing room. If there is, good, else, we'll be called back with OnJoinRandomFailed()  
            PhotonNetwork.JoinRandomRoom();
            Debug.Log("Joined room " + PhotonNetwork.CurrentRoom.Name);
        }
    }

    public override void OnDisconnected(DisconnectCause cause)
    {
        Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
    }
The Connect() function is called through a UI button

How do I delete the buffer data of a specific "rpc"?

$
0
0
How do I delete the buffer data of a specific "rpc"?

can be removed


How to fix Cannot remove cached RPCs on a PhotonView thats not ours! scene: True?

$
0
0
I have this message in the console and I am having trouble finding the source of the problem. There are no resources on the internet related to this issue. I can provide whatever you think is needed to find the fix

I am having receiving Masterclient error from Photon Unity Classic

$
0
0
Hello, I am running Unity 2017.4.6f1 and the latest version of PUN classic from the asset store. Trying to integrate Photon on an old project and receiving an error from this line if (!this.CurrentRoom.serverSideMasterClient) this.CheckMasterClient(-1); in NetworkPeer.cs at line 1293. I believe it stems from this section of code from Room.cs protected internal int MasterClientId { get { return this.MasterClientId; } set { this.MasterClientId = value; } } I am having trouble understanding this issue directly since it is pure PUN networking not my typical coding expertise. I just know C# and how to implement the core of Photon. I belive it is from this.MasterClientId = value specifically value What is a fix to this issue? Any help would be much appreciated :)

NullRef in RPC() error handling when function name is wrong and there is no parameter (Pun 2.9)

$
0
0
Hello, I haven't updated to the newest Pun but there's nothing about this bug in the 2.11 and 2.12 changelog (haven't seen the 2.10 changelog as it's not on the asset store). If I call PhotonView.RPC() with a function name that has a typo, and the RPC call has zero custom arguments, then I get this nullref: NullReferenceException: Object reference not set to an instance of an object Photon.Pun.PhotonNetwork.ExecuteRpc (ExitGames.Client.Photon.Hashtable rpcData, Photon.Realtime.Player sender) (at Assets/Tools/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:506) In case the code in PhotonNetworkPart.cs has changed since 2.9, here are the offending lines:
            // Error handling
            if (receivers != 1)
            {
                string argsString = string.Empty;
                for (int index = 0; index < argumentsTypes.Length; index++)
(more specifically the last one)

PRC call error,when the two same components in a gameobject

$
0
0
I have a component called shooter. And I have multi shooter components on my player game object. If I use PRC call shoot function of a shooter. It will cause an error, "NullReferenceException: Object reference not set to an instance of an object" I think it caused by multi shoot function in the same gameobject, but I need many shooters in my player gameobject so I can stack many shooting ways up. How can I tackle this issue?

enablesupportlogging + running + notconnected + recompile = exception

$
0
0
If you: - have enablesupportlogging enabled - are running the game in editor - haven't connected to photon yet - trigger a recompile (ie code hot-reload) You get an exception here repeatedly:
SupportLogger.TrackValues()    Assets/Photon/PhotonRealtime/Code/SupportLogger.cs:145
This component gets added automatically from here (stacktrace):
SupportLogger.Awake()    Assets/Photon/PhotonRealtime/Code/SupportLogger.cs:87
GameObject.AddComponent()
PhotonHandler.OnEnable()    Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:98
GameObject.AddComponent()
PhotonHandler.get_Instance()    Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:41
Photon.Pun.PhotonNetwork..cctor()    Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1005
PhotonEditor.OnCompileStarted()    Assets/Photon/PhotonUnityNetworking/Code/Editor/PhotonEditor.cs:206
EditorCompilationInterface.TickCompilationPipeline()
I don't expect hot reload to work with a running networked game, however this breaks hot-reload even when you're not networking. (by break only symptom is the exception, which is not the end of the world but it is annoying). (not sure if there's a better place to report bugs)
Viewing all 8947 articles
Browse latest View live


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