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

How to fix matchmaking when only a few users are existing?

$
0
0
Hi Photon Community!

In my project, matchmaking works in a way now is that it search for available rooms and checks if there's any user in them. And if not, then it starts a room itself and wait for users to join.

It works perfectly when one of the users waits until it has created its room, and when it starts to joining, it finds the room and joins. No waiting would be needed if there would be more rooms to join, so there would be 5-10 users.

But the problem is for example when there're only two players, and the two players start the matchmaking at the same time, there's a chance that they can't find each other. They both try to find a different room, and they both create a room on their own.

What is the best practice of solving this? Creating room and waiting first, and joining to a different room after a few seconds?

[Playmaker] Globals variable not work on cloud build after playmaker PUN2 addons installed

$
0
0
hi, i have install PUN2 asset and PUN2 playmaker addons form ecosystem, and start cloud build.
apk will build success, but on the app will not work for any Globals variable. it seem null of Globals variable in the app.
PlayMaker: 1.9.2.f3
Unity: 2020.3.14f1
Android
PUN2: 2.33.3

Anyone use playmaker PUN2 and cloud build can give some suggestion?
thanks.

How to not destroy Player Objects when disconnected

$
0
0
Currently, when a client disconnects, photon is automatically destroying all objects created by this client. Example, your player object.

I plan to keep the player prefab instantiated for this client even when it exits the game. I don't want it to be destroyed, as I must replace this client's logic with an artificial intelligence.

The emptied room still presents, and custom properties became null

$
0
0
Tested with 2 players, and Player A in the room list view which displays the list of the rooms and can pick up the room to join. Another Player B, just created a room and waiting for joining other players.

When Player B created a room, Player A receives OnRoomListUpdate Callback and updates the list of the rooms. But, right after Player B left the room, Player A receives OnRoomListUpdate callback again, but the room is still over there with 0 players. The problem is that this room never disappears until Player A forcibly refreshes the server list by disconnect from the PhotonNetwork and connect again, or someone else creates another server so that A receives OnRoomListUpdate callback again.

And the second problem is that I'm using custom properties, and when Player B left the room and Player A receives ListUpdate callback, the room still exists but all custom properties go null which throws a null reference exception.

Using Unity 2019.1.0f2 and Pun 2.33 lib 4.1.6.3, just downloaded from the asset store.

Photon App Crashes on Join

$
0
0
My client did a demo with the app I built, and said the app crashed as soon as someone else joined. They were both able to run the app individually, but when someone joined, it crashed. The client and I have been able to play multiplayer, and I've been able to play with another phone I have(3 player, including the editor).

So I'm guessing the person he was demoing to was in another region and that was the issue? I have the fixed region set to Asia, but is there some issue caused by joining a server, I don't know, say the region was set to Asia and one person from Asia joined and another from America joined? But if that was the issue, why would the first person be able to join no problem, but as soon as the second joined it crashed? My client said the issue occurred the same if one or the other joined first, it would crash when the second person joined.

Here's a screenshot of my settings FmNOa34.png

Would anyone be able to help me fix this? Thanks.

Issue with synchronizing rotation

$
0
0
I have an issue with synchronizing my characters rotation.

The character has these things attatched:
CapsuleCollider, Rigidbody,
PhotonView, PhotonRigisbodyView, PhotonTransformView, PhotonAnimatorView,
NetworkPlayerPhoton

When entering a Map, the character (the MeshPlayer) is being spawned and made as a Child of an EmptyGameObject called "Player".
The "Player" GameObject has the PhotonView and PhotonTransformView attatched.

When I build the Game and run it on 2 Android devices, and move a character, on the other Device the position of the character is being updated but not the rotation of it and also not the ("Run" Animation).


This is the NetworkPlayerPhoton Script which is there for synchronizing everything:

public class NetworkPlayerPhoton : MonoBehaviourPun, IPunObservable
{
    private Transform character;
    private Transform personalCamera;
    private FGroundFitter_Demo_JoystickInput joystickInput;
    private SingleAttack singleAttack;
    private AnimalTigerRoar animalRoar;

    private Rigidbody r;

    //For smoothing the Movement of other Characters
    Vector3 latestPos;
    Quaternion latestRot;
    Vector3 velocity;
    Vector3 angularVelocity;

    bool valuesReceived = false;

    //Link the Animator
    private Animator animator;


    private void Start()
    {
        if (photonView.IsMine)
        {
            GetComponent<FGroundFitter_Demo_JoystickInput>().enabled = true;
            GetComponent<SingleAttack>().enabled = true;
            GetComponent<AnimalTigerRoar>().enabled = true;
            personalCamera.gameObject.SetActive(true);
        }
        else
        {
            Destroy(character);
            Destroy(this);
        }
    }

    private void FixedUpdate()
    {
        GetNeededComponents();
    }

    private void GetNeededComponents()
    {
        GameObject temporaryCamera = GameObject.FindGameObjectWithTag("Camera");
        personalCamera = temporaryCamera.transform.GetChild(0);

        GameObject temporaryPlayer = GameObject.FindGameObjectWithTag("Player");
        character = temporaryPlayer.transform.GetChild(0);

        joystickInput = GetComponent<FGroundFitter_Demo_JoystickInput>();

        singleAttack = GetComponent<SingleAttack>();

        animalRoar = GetComponent<AnimalTigerRoar>();

        animator = GetComponent<Animator>();

        r = GetComponent<Rigidbody>();
    }


    //Send the Character Position and Rotation through the Server
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            // We own this player: send the others our data
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            stream.SendNext(r.velocity);
            stream.SendNext(r.angularVelocity);
            stream.SendNext(animator.GetBool("Walk"));
            stream.SendNext(animator.GetBool("Run"));
            stream.SendNext(animator.GetBool("Sound"));
            stream.SendNext(animator.GetBool("Attack"));
        }
        else
        {
            // Network player, receive data
            latestPos = (Vector3)stream.ReceiveNext();
            latestRot = (Quaternion)stream.ReceiveNext();
            velocity = (Vector3)stream.ReceiveNext();
            angularVelocity = (Vector3)stream.ReceiveNext();
            animator.SetBool("Walk", (bool)stream.ReceiveNext());
            animator.SetBool("Run", (bool)stream.ReceiveNext());
            animator.SetBool("Sound", (bool)stream.ReceiveNext());
            animator.SetBool("Attack", (bool)stream.ReceiveNext());

            valuesReceived = true;
        }
    }

    private void Update()
    {
        if (!photonView.IsMine && valuesReceived)
        {
            //Update Object position and Rigidbody parameters
            transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 5);
            transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 5);
            r.velocity = velocity;
            r.angularVelocity = angularVelocity;
        }
    }

    void OnCollisionEnter(Collision contact)
    {
        if (!photonView.IsMine)
        {
            Transform collisionObjectRoot = contact.transform.root;
            if (collisionObjectRoot.CompareTag("MeshPlayer"))
            {
                //Transfer PhotonView of Rigidbody to our local player
                photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
            }
        }
    }
}

Round System Photon

$
0
0
Hi I'm doing a round system and I want to make that if I kill all the other teams and when I kill all of them I get a point, I did an int for the two teams, and then if it reaches 0, you add a point, but the problem is that I try but if someone leaves Photon takes 1 from the two teams with the PlayerLeftRoom, but there is also another problem and it is that sometimes I will say that there are 3 in the red team but in the game, there is 1 in the red team and 2 from the blue team, so I don't know what to do if someone knows another way please tell me

Ragdoll rigidbody parts not synchronizing when animator turned off

$
0
0
i made a multiplayer fighting based game, and added ragdoll mode when you get knocked out.
everything works fine in code until... when i get knocked out i turn off the animator and turn on ragdoll mode which works fine on my screen, but player 2 screen the player is static and not moving .. does anyone has any suggestions on how to tackle this problem.

Thank you

Loading different scenes from one room.

$
0
0
Hello

Just started using PUN2. Here is what I have. I Have my first scene which NetworkManager object with two scripts attached. The first script connects to the server and creates or joins a room for two players if one already exists. The second script instantiates the player prefab objects both via the photon.Network and local game instance. My issue arise when i try to photon.Network.loadLevel another scene with the master client. Basically what happens is that neither of the player instances appear in the new scene. What I would like to do is to load a new scene with both of the players from the first scene. I want each player to be able to see each other and interact with objects inside this scene. Ones a specific goal is meet I want this new scene to load another scene which fallows withing the buildindex.

Somehow every object that I spawn got destroyed

$
0
0
I've stumbled upon this strange behavior. I am spawning a couple of objects in the start of the scenes, with help of PhotonNetwork.Instantiate(). Everything work just fine in build. But in the editor, everything is getting destroyed after it spawns, for some reason. Please help, it is getting annoying)

How to run a RPC Coroutine?

$
0
0
Hi, I am trying to make a bullet script where 2 sounds play after the other after a certain amount of time after the bullet is shot so than all players can hear it but it seems like when I do photonView.RPC("Coroutine", RpcTarget.All) it does not work because it is not starting the coroutine and it just spams my console when it gets to the yield return new WaitForSeconds()

here is my code
void Update()
    {
        if (photonView.IsMine)
        {
            if (Input.GetKey(KeyCode.Mouse1))
            {
                scope.SetActive(true);
                crosshair.SetActive(false);
                if (Input.GetKeyDown(KeyCode.Mouse0) && !isPlaying)
                {
                    isPlaying = true;
                    photonView.RPC("RPC_PlaySound", RpcTarget.All);
                }
            }
            else
            {
                scope.SetActive(false);
                crosshair.SetActive(true);
            }
        }
    }

    [PunRPC]
    IEnumerator RPC_PlaySound()
    {
        AudioSource sound = gun.transform.Find("Sound1").GetComponent<AudioSource>();
        AudioSource sound2 = gun.transform.Find("Sound2").GetComponent<AudioSource>();
        flashEffect.Play();
        photonView.RPC("RPC_Fire", RpcTarget.All);
        sound.Play();
        yield return new WaitForSeconds(2);
        sound2.Play();
        yield return new WaitForSeconds(0.5f);
        isPlaying = false;
    }

    [PunRPC]
    public void RPC_Fire()
    {
        bullet = Instantiate(bulletPrefab);
        bullet.transform.position = bulletSpawn.position;
        Vector3 rotation = bullet.transform.rotation.eulerAngles;
        bullet.transform.rotation = Quaternion.Euler(rotation.x, transform.eulerAngles.y, rotation.z);
        bullet.GetComponent<Rigidbody>().AddForce(bulletSpawn.forward * bulletSpeed, ForceMode.Impulse);
        StartCoroutine(DestroyBulletAfterTime(bullet, lifeTime));
    }

    IEnumerator DestroyBulletAfterTime(GameObject bullet, float delay)
    {
        yield return new WaitForSeconds(delay);
        Destroy(bullet);
    }
This has been making me pull my hair out for ages and I am unsure how this would work

Networking Models Imported at Runtime

$
0
0
Hello,
We are importing gltf models at runtime and want them to be networked between all players. We will have each player import the model individually through a networked drive, however there's some issues getting things like transforms networked after this. Has anyone tried this before or have general advice?

Photon Instantiate Prefab(Not Visible)

$
0
0
Hello,

I am instantiating a prefab and using RPC to send the details of the positions to the clients to set the prefab correctly , but the problem is when I am using a slow mobile phone being the master client the instantiated prefab cannot be seen on a fast processing phone it just disappears.
Please Could you help me regarding this




Thanks and Regards,
PILLA HARISH

photon game not responding ?

$
0
0
hi, i'm making a multiplayer game using photon and after building the game the first level and playing a bit,in the second or third scene switch (not consistent) the non master client game freezes (Not responding) with no errors even when it's the editor.i've checked every isMasterClient test i've made, and none of them seem to be causing the problem, any idea what could be causing this, is there a specific thing i should be looking for?

Thanks <3

General informations needed

$
0
0
Hi,
We are a team of 6 french people and we are doing an internship. We have to create a videogame and we want it to be multiplayer.
We are currently using the photon PUN free (20 CCU) but we wanted to buy the 100 CCU subscription. We are working for a local authority and they won't accept to pay for it because they did not find enough informations about sales conditions.

I am trying to gather these informations.

- The subscrition for 100 CCU is a 12 months subscription, what happens after 12 months (will the game return to the 20 CCU option or will another 12 months subcription start ? Do we have to do something to change it?)

- For the 100 CCU subscription, do we have to pay for the 12 months at once or each month ?

- If we pay for a year, can we still downgrade to the 20 CCU option whenever we want ? (I know that we won't be refunded).
-
- The bank account is french, is it a problem ? Or is it possible to pay with it ?

- We can pay with paypal or creditcard, are there other options (bank transfer for example) ?

- Is there any document that explains the general sales conditions that I could send them ?

Countdown Timer Sync on network

$
0
0
Hello, I want a countdown timer to be synchronized across all clients. I have seen some other forums regarding this but they are quite old or maybe they still work and I missed something. Can someone help?

using PhotonNetwork.ConnectUsingSettings(); do not connect and gives error in unity WebGl browser.

$
0
0
(unity version 2019.3.5 , Pun 2 . version 2.28.)

Here is the start function that im using to connect.

void Start()
{
PhotonNetwork.GameVersion = "1.0";
PhotonNetwork.ConnectUsingSettings();
}

it works fine in unity editor but not in the browser. i have my domain and hosting, The scene loads fine but when the PhotonNetwork.ConnectUsingSettings(); called it gives following error

[style color="Red"] Connect() failed to create a IPhotonSocket instance for WebSocketSecure. SocketImplementationConfig: {Udp=ExitGames.Client.Photon.SocketUdp, Tcp=ExitGames.Client.Photon.SocketTcp, WebSocket=ExitGames.Client.Photon.SocketWebTcp, WebSocketSecure=ExitGames.Client.Photon.SocketWebTcp} Exception: System.MissingMethodException: Constructor on type 'ExitGames.Client.Photon.SocketWebTcp' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
[style]

This is the PhotonServerSettings.

[img]file:///C:/Users/Welcome/Documents/photonserversettings.PNG[/img]

i've tried different solutions, There was a fix on website but this is already implemented in this version of PUN2.
file:///C:/Users/Welcome/Documents/fix.PNG

Help me solving this problem, Thanks

Collision detection beetween clients

$
0
0
I am working on a project that is adding bots to the multiplayer setting. Right now they are instatiated as room objects and work properly beetween the clients that connect. But there is a problem with one the game systems. The game is an plane fight arena, after one minute of game has passed a dome appears and anyone outside it will start to take damage. Right now the systems detects everyone that has a "PlayerController" and sees if it is inside or outside the area, if it outside a bool changes that enables the damage tick.

The problem is, the bots only get detected by the master client instance of the "SafeZone detector", the other clients only see themselves. So if the masterclient leaves the room, the bots keep their bools as is (If they were safe now they will be for the rest of the game, dosn't matter if they exit the safe zone or not) and will not update anymore. I used Debugs to see that only the masterClient was seeing the bots in the collision, and when he disconnects the new MasterClient only sees himself (Like before he was the master). I don't know why the collision only works in the first master client, even thought the bots are room objects

Unity Version: 2018.4.27.f1
Photon Pun: 2.21
Photon lib: 4.1.4.4

Xbox Series Suspend Crashes Build On Resume

$
0
0
Hi,

While connected to photon and in a room, we suspend/resume our app and we get this error right after the resume.
ERROR websocketgamecore.cpp ExitGames::Photon::Internal::WebSocketConnect::handleSendError() 284 Failed to write to web socket! 
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) 5866UnityEngine.Logger:Log(LogType, Object) 
UnityEngine.Debug:LogError(Object) 5868Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.<>c__DisplayClass110_0:<EnqueueDebugReturn>b__0() 
ExitGames.Client.Photon.TPeer:DispatchIncomingCommands() 
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() 
Photon.Pun.PhotonHandler:Dispatch() 
Photon.Pun.PhotonHandler:FixedUpdate()

This has been tested on Xbox Series X. Unity 2020.3.12f1. PUN v2.30

Is there anything we need to do before suspending or everything should already be handled gracefully within Photon?

Thanks.

teleport player to other player - platformer multiplayer

$
0
0
help me to achieve this goal , please

i used this to move toward player , but the problem is how to get other player position ?

transform.position = Vector2.MoveTowards(transform.position, targetC.transform.position, 15f * Time.deltaTime);


Viewing all 8947 articles
Browse latest View live


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