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

Server logic for Unity simple game

$
0
0
There is a task: an online 1vs1 pin-pong game where you can bet your in-game currency. There are (for example) 3 game modes with a bet of 5, 20 and 100 coins. The player chooses which bet he wants to play and queues, then the second player queues for the same bet and a room is automatically created for them where they play against each other up to 10 points to win. It is desirable to implement the selection of opponents by skill/experience of the game. So the beginners play with beginners, and experienced with experienced (logic on the server). Again, the rooms should be automatically generated. There should be no lobby with a visible list of rooms, only the choice of a bet and the expectation of an opponent. The winner gets the full bet (without any fee). There must be a database to save the results and settings of each player. Authorization through social networks and email. Protection against cheaters is a low priority. How I planned: All physics and logic takes place on the client side. The server creates rooms for the players that waiting for opponents and provides the exchange of platforms location via UDP, and important messages/events via TCP. There will be no game physics and logic on the server side. This server will be connected to the database to save information, leaderboards and number of collected coins and so on ... Main tasks: C # server for Unity Own logic on the server Ability to work with the database. I wanted to use Photon server for these tasks, but I cannot understand if it is possible to bind a database, for example, MySQL, and process minimal logic on the server, is it possible at all? What server besides Photon is suitable for this project?(preferably free). I will be glad to recieve some help and to find the correct way to solve this problem. Thanks.

Is there a way to select region?

$
0
0
I'm looking through a tutorial on how to do a room browser and that part is all very straight forward but I'd like to see if it's possible to do a drop down menu that gives the players freedom to select which region they want to make a room in. I did some research on this already and apparently there are restrictions on doing this type of thing? Could somebody correct me if I'm wrong or if there's been some kind of change I'd just like to know. Just to be clear, I'm not talking about the server settings, I'm talking about implementing a drop down menu within the actual project.

PUN v2 Ownership Callbacks

$
0
0
Hi all. I'm trying to clarify the best approach to using Ownership callbacks. I understand how to take ownership of a Scene object. I want to be able to detect when a PhotonView has changed ownership so I can have logic that checks, am I the new owner Yes or No. I have implemented the IPunOwnershipCallbacks on my MonoBehaviour (parent of my PhotonView) however neither callback appears to be called despite successful ownership transfer. As my PhotonView Owner is set to Takeover I understand OnOwnershipRequest would not fire (there was no request), but when the takeover is completed I would expect OnOwnershipRequest to. There is no PUN v2 version of the Ownership Transfer Demo that exists in the Pun v1 documentation https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/package-demos/ownership-transfer cheers

NPC Moving event not synchronized between players

$
0
0
Hey! I have an event where you talk to an NPC and they start moving. The event runs just fine on the host side- it shows in both the clients and the host. But when the client starts the event it's not triggered on the server at all. Any clue to why this could happen? I'm new to Networking so I could be missing something big here. Here are the PUN related settings of the NPC object, and a video to demonstrate the problem. https://vimeo.com/318202524

Fast paced online game without client side prediction

$
0
0
I'm wondering if there is fast paced online game that client only lerp position in the past, and how good it can be? My friend told me that game should design this way , and I should not care about high ping player.

RPCs after Player reconnected

$
0
0
Hi I made some board games but my big problem in all of them is: When one player is disconnected and reconnected after some second, RPCs are called and new player sees some fake moves in wrong time. For example, I throw dice and then move . opponent disconnect and Reconnect. he sees i throwing dice and move again.how i can manage RPCs when the player is reconnected?

AuthSettings

$
0
0
Hi! I'm trying to handle reconnect routine. I have a player that creates new room, loses connection, reconnects to master and then rejoins the room. Everything goes well with AuthSettings set to true. If AuthSettings is set to false, reconnect goes well and rejoin attempt leads to an error: Operation failed: OperationResponse 226: ReturnCode: 32746 (Join failed: UserId '00000000-0000-0000-0000-000000000000' already joined the specified game (JoinMode=3).). Parameters: {} Server: GameServer So what exactly does AuthSettings set to true? Is there any way to rejoin without setting it to true? Maybe there's something I did wrong? Why is UserId equal to '00000000-0000-0000-0000-000000000000'? P.S. I'm sorry for my English!

Is there a tutorial or bit of documentation out there for listing the players killed?

$
0
0
https://d1jkho2idshhnx.cloudfront.net/blog/wp-content/uploads/2016/08/csgo-aces.jpg I'm looking now at more stuff now that I'm slowly wrapping my head around networking and I wanted to create a player kill list like the one in the top right. I know how to get things like the nickname of the client player and other players fine but I have no idea how I'd implement a kill list.

Sending level over to other players

$
0
0
Hello, I have a leveldesigner in my game where every player can create his own levels. I want the host to be able to play a level that he created without the other players need to download it from anywhere. (Stronghold Crusader for example manages to do this) If I send the data via RPC the level gets loaded but the connection drops after its done loading. I can load it without getting cicked if I yield a second but it takes forever to load if I do it like this. This gets called for every chunk from another object when loading the scene: [PunRPC] public void Load(Vector3 position, Vector3[] vert, Vector3[] norm, Vector2[] uv, int[] tri, bool fluid) { Material _material = null; Transform _parent = null; if (!fluid) { _parent = LoadIngameLevel.GetInstance.Level.GetChild(0); _material = LoadIngameLevel.GetInstance.normalMaterial; this.gameObject.tag = "Chunk"; } else { _parent = LoadIngameLevel.GetInstance.Level.GetChild(1); Fluid _fluid = this.gameObject.AddComponent(); } transform.SetParent(_parent); transform.position = position; Mesh mesh = new Mesh(); MeshFilter meshFilter = (MeshFilter)this.gameObject.AddComponent(); MeshRenderer meshRend = this.gameObject.AddComponent(); meshRend.material = _material; mesh.vertices = vert; mesh.normals = norm; mesh.uv = uv; List suvs = new List(); mesh.SetUVs(1, suvs); mesh.triangles = tri; mesh.RecalculateBounds(); meshFilter.mesh = mesh; MeshCollider meshCol = this.gameObject.AddComponent(); meshCol.sharedMesh = meshFilter.mesh; } Please help! Thanks alot!!

Can I call and receive RPC function when application goes to background?

$
0
0
Hello @JohnTube How are you On Android/iOS, when the app goes to background, RPC function is not calling. And can't receive. Maybe Update() function is not calling in Unity when goes to background. Please tell me the proper way to allow the application to call the RPC function even if the app is in the background. Also, I want the timer working in the background. Well... this problem is mainly based on Unity, but I just want to get a great answer from you :smile: I will be waiting for your kind answer. Thanks

Client Version not working

$
0
0
Hello, So, I have this problem with PUN where I set the GameVersion but it dosen't work, I have 2 clients, one with version "v0.35" and one with "v0.36" and they still connecting to the same room. Code: PhotonNetwork.NickName = nickName; PhotonNetwork.GameVersion = Application.version; PhotonNetwork.ConnectUsingSettings(); Application .version is returning the right value.

No match found - Join Random Room

$
0
0
No matter what I try, both clients create separate rooms and when calling to join random they both say no match found. using UnityEngine; using Photon.Pun; using Photon.Realtime; public class MenuNetwork : MonoBehaviourPunCallbacks { public static MenuNetwork Network; private void Awake () { Network = this; } [Header("Adjustable")] public float maxWaitTime = 20f; public bool debugMode = false; public float fakeDelay = 1f; public int levelToLoad = 1; [Header("References")] public GameObject connectingUI; public GameObject quickmatchButton; public GameObject searchingUI; [Header("Observe Only")] [SerializeField] private float delay; [SerializeField] private bool searching = false; [SerializeField] private float waitTimer; private void Start () { delay = fakeDelay; waitTimer = maxWaitTime; PhotonNetwork.AutomaticallySyncScene = true; PhotonNetwork.ConnectUsingSettings(); } public override void OnConnectedToMaster() { if(debugMode) Debug.Log("(Network) Connected to Master Server"); CreateRandomUsername(); connectingUI.SetActive(false); quickmatchButton.SetActive(true); } private void CreateRandomUsername () { PhotonNetwork.NickName = "User " + Random.Range(100, 10000).ToString("N0"); } public void OnClick_Quickmatch() { searching = true; quickmatchButton.SetActive(false); searchingUI.SetActive(true); } public void OnClick_Cancel () { searching = false; PhotonNetwork.LeaveRoom(); quickmatchButton.SetActive(true); searchingUI.SetActive(false); } private void Update () { if(searching) { delay -= Time.deltaTime; if (delay <= 0) { searching = false; PhotonNetwork.JoinRandomRoom(); delay = fakeDelay; } } // end of if searching // DEBUGGING if(PhotonNetwork.InRoom) { Debug.Log("Is Host? " + PhotonNetwork.IsMasterClient); Debug.Log("Players: " + PhotonNetwork.CurrentRoom.PlayerCount + "/" + PhotonNetwork.CurrentRoom.MaxPlayers); } if(PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient) { // If there are 2 or more players if(PhotonNetwork.CurrentRoom.PlayerCount > 1) { waitTimer -= Time.deltaTime; if (waitTimer <= 0) { Host_StartMatch(); waitTimer = maxWaitTime; return; } // If we're at the max players if (PhotonNetwork.CurrentRoom.PlayerCount == PhotonNetwork.CurrentRoom.MaxPlayers) { waitTimer = maxWaitTime; Host_StartMatch(); return; } } } // end of if in room & host } public override void OnJoinRandomFailed(short returnCode, string message) { Debug.Log("OnJoinRandomFailed: " + message); CreateRandomRoom(); } private void CreateRandomRoom () { int generatedID = Random.Range(0, 9999999); RoomOptions roomOptions = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 4 }; PhotonNetwork.CreateRoom("Quickmatch " + generatedID.ToString("N0"), roomOptions); //PhotonNetwork.CreateRoom(null); } public override void OnCreateRoomFailed(short returnCode, string message) { base.OnCreateRoomFailed(returnCode, message); Debug.LogError("Failed to create room? Trying again!"); CreateRandomRoom(); } public override void OnJoinedRoom() { Debug.Log("(Network) Connected to room " + PhotonNetwork.CurrentRoom.Name); searching = false; } private void Host_StartMatch () { PhotonNetwork.LoadLevel(levelToLoad); } }

Detect other player has QUIT the application, not just disconnected

$
0
0
Hello, I'm trying to implement a reconnect feature to our game. It's a 1v1 game so have 2 players in a room. So far, I can detect when the player gets disconnected due to a network issue using OnDisconnected() and OnPlayerLeftRoom(), and display a dialog while waiting for the other player to reconnect. However, I want to detect when the other player actually quits the application, and have the remaining player win immediately. Currently, I don't know of a way to distinguish whether the other player just got disconnected or has actually quit the application. Because of this, when the other player quits the application, the remaining player gets the waiting to reconnect dialog instead of winning immediately. I thought of implementing OnApplicationQuit(), thinking I would send an event to the remaining player before the application is closed, but more often than not by the time OnApplicationQuit() is called, Photon has already been disconnected, so I can't send events anymore. What should be the right approach to this? Thanks

Problem with cross platform connection

$
0
0
Hi! I'm currently working on a multiplayer turn-based game, and I'm using Photon for the networking part. When I run multiple instances of the game on my pc, the game works flawlessly, but when I create a room on my pc, and connect to that room from an Android phone, it won't find the room. I've been having this problem for days and I still haven't managed to solve it. Any thoughts?

PhotonNetwork.Instantiate not working (Unity / Pun2)

$
0
0
I currently have a problem with trying to instantiate spell prefabs. At first I guess the best thing is to show the used code:
public abstract class BaseSpell : ScriptableObject {
    protected GameObject spawnSpellPrefab() {
        var newSpellObject = PhotonNetwork.Instantiate(spellPrefab.name, new Vector3(0, 0, 0), Quaternion.identity, 0);
        SpellPoolManager.instance.addTimedObjectToPool(newSpellObject, despawnTime);
        return newSpellObject;
    }
}
(Note that the SpellPoolManager does not cause this) Then I have subclasses of the baseclass that then use the spawnSpellPrefab to Instantinate the Prefab:
public class SFireBall {
    protected override void onKeyUp() {
        var newSpellObject = spawnSpellPrefab();
        [...]
    }
}
Those spells are referenced by the player which then can spawns those per key press which works perfectly fine both in offline and the local client that initiates the spell. However the other player does not see the spell at all. Following error message appears:
Received OnSerialization for view ID 2002. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined
The spellPrefab, which is supposed to spawn, has a PhotonView Script attached and rests in the Resources Folder. I have red through the tutorial page (https://doc.photonengine.com/en-us/pun/v2/gameplay/instantiation) now at least a dozen times and still can't figure out what the problem is. Here is the spellPrefab Inspector: Inspector View So either I'm doing something completely wrong, or you can only Instantiate Prefabs from an active GameObject, still thank you in advance for you help and time!

Room and player custom properties

$
0
0
Hello, I want to know if there is a way of passing a player propertie value in "expectedValues" but setting the room properties, something like this. var propertiesToSet = new Hashtable() { {"whateverKey", "whateverValue"} } var expectedProperties = new Hashtable() { {"SomePlayerActorNumberHere.whateverKey", "whateverValue"} }; PhotonNetwork.CurrentRoom.SetCustomProperties(propertiesToSet, expectedProperties);

Issues after following Pun-Basic tutorial

$
0
0
So I've noticed a few peculiarities after following this tutorial: https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro First off, if I try and attach Visual Studio to Unity for debugging, it will freeze when the new scene is trying to load, so it makes it quite hard to test. Second, attached to my player prefab is the "cameraWork" script, and in the "playerManager" script, in the start() mono method we check the following: CameraWork _cameraWork = gameObject.GetComponent(); if (_cameraWork != null) { if (photonView.IsMine) { _cameraWork.OnStartFollowing(); } } else { Debug.LogError("Missing CameraWork Component on playerPrefab.", this); } However, even though there is a cameraWork script attached I always get the missing component error. Any ideas as to why this is the case? Also, the PUN-Basics scenes that come with PUN2 don't quite match the tutorial and I was wondering why.

How to Reference other player's object spawned with PhotonNetwork.Instantiate() ?

$
0
0
Each player get something like: GameObject foo = PhotonNetwork.Instantiate("PlayerPrefab", ...); foo.something = bar; // Goal Operation to perform on other's PlayerPrefab in the local Client This only work for the owner of the object however, as the version spawned automatically will not run this code. What is the correct/best way to fetch a reference to the other player's "PlayerPrefab" in this case? Thank you.

Child Status of gameobject is only visible by local client

$
0
0
Hello, so I used photonnetwork.instantiate one of my prefabs and then I turn it into a child. This code works but only for the local client even when I have photon view attached to my prefabs and animation+transform view. Any suggestions because I'm pretty lost with this one Snips of my code + setups. Most of the Photon Views in the scripts are set to be public rather than private https://imgur.com/ecCAGKd https://imgur.com/a/aG0JSJ2

Syncing Bone Rotations

$
0
0
Here is the script that I use to sync bones but for some reason its not syncing void OnAnimatorIK() { if(PV.IsMine) { anim.SetLookAtWeight(0.7f, 0.5f); anim.SetLookAtPosition(targetFocus.position); } } void Update() { if(PV.IsMine == true && _syncBones == true) { if (currentBoneRate == _syncBonesRate) { currentBoneRate = 0; PV.RPC("RPC_UpdateBoneRotations", RpcTarget.AllBuffered, local_head.localRotation, local_neck.localRotation, local_spine.localRotation, local_chest.localRotation); } else { currentBoneRate += 1; } } if (_syncBones == true && PV.IsMine == false) { Debug.Log("Attempting to sync bones for other clients"); local_head.localRotation = Quaternion.Lerp(local_head.localRotation, correctBoneHeadRot, Time.deltaTime * _boneLerpRate); local_neck.localRotation = Quaternion.Lerp(local_neck.localRotation, correctBoneNeckRot, Time.deltaTime * _boneLerpRate); local_spine.localRotation = Quaternion.Lerp(local_spine.localRotation, correctBoneSpineRot, Time.deltaTime * _boneLerpRate); local_chest.localRotation = Quaternion.Lerp(local_chest.localRotation, correctBoneChestRot, Time.deltaTime * _boneLerpRate); } } [PunRPC] void RPC_UpdateBoneRotations (Quaternion h, Quaternion n, Quaternion s, Quaternion c) { Debug.Log("SyncingBones"); correctBoneHeadRot = h; correctBoneNeckRot = n; correctBoneSpineRot = s; correctBoneChestRot = c; }
Viewing all 8947 articles
Browse latest View live


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