I have a script that I use as a game manager which has a view owned by the scene. It holds the value for each player's character and their player ID.
I noticed that when running as first player, I am not able to see the second player's values in the inspector when player 2 updates the player 2 variables. However, player 2 gets player 1's values.
For example, when you first join the room, if you are the master client, the variable p1Username is updated. If you are not the master client, p2Username is updated.
The master client will only seen p1Username being populated. The second player will see p1Username and p2Username populated.
The same thing happens on the character select screen. When the select button is hit, player 1 can only see his own character name in the inspector but the variable for p2username is blank. However, player 2 can see both names populated in the inspector.
Am I missing something? I have the object being instantiated with PhotonNetwork.InstantiateSceneObject("MultiGameManager", transform.position, Quaternion.identity, 0, null);
It has a view object that references the script and is set to unreliable. I've also tried unreliable update and reliable.
What am I missing?
↧
Player 2 OnPhotonSerializeView is updated and Player 1 is not?
↧
PUN 2 Problem
I have a problem here with Photon's PUN 2. Sometimes It works, but other times it doesn't. Since the last 2 weeks it isn't working that fine. Before it were better, I joined to the master, and then, to the lobby and It allowed me to list the rooms and join them without any problem. Now, I haven't changed that code that much, I only changed it after the errors started. Now, sometimes it joins a match, but another it doesn't, showing the following error:
JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.
I only have 2 devices to test my online with PUN, but, even if I created a room is not working anymore, it just seems like works randomly. Here's my code if you want to check it:
void Start()
{
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
//This shows a popup to let know the player that is connected
//PhotonNetwork.JoinLobby();
base.OnJoinedLobby();
GameObject.Find("IWifi").SetActive(false);
print("Puga");
StatePScript.IsShow = true;
Connected = true;
GameObject.Find("IOk").GetComponent().color = Color.white;
print("IOKS Value is " + IOKS.Show);
GameObject.Find("StatusText").GetComponent().text = "Connected!";
GameObject.Find("StatusText").GetComponent().color = Color.green;
A.Play();
GameObject.Find("StatePanel").GetComponent().SetBool("Show", false);
IOKS.Show = false;
GameObject.Find("IOk").GetComponent().color = new Color(0, 0, 0, 0);
Connected = false;
StatePScript.IsShow = false;
}
I have other photon scripts like this that is the random room code:
using Photon.Pun;
public class RandomBScript : MonoBehaviourPunCallbacks
{
private Button B;
void Start ()
{
B = GetComponent
The create room code:
using Photon.Pun;
public class CreateRoomS : MonoBehaviourPunCallbacks
{
private Button B
private InputField IF;
private InputField PlayerField;
public AudioSource A;
void Start ()
{
B = GetComponent
And finally, the list rooms code:
using Photon.Pun;
using System;
public class RooManager : MonoBehaviourPunCallbacks
{
public GameObject roomPrefab;
public Sprite Four, Two, Three;
private string RoomName;
private int PlayerAmount;
private int MaxPlayers;
private Image I;
private Vector2 RoomVector;
private bool Lock = false;
public GameObject Content;
private List RoomList;
private bool IsntNull = false;
private Dictionary cachedRoomList;
private Dictionary roomListEntries;
private void Awake()
{
GameObject.Find("StatePanel").GetComponent().SetBool("Show", true);
cachedRoomList = new Dictionary();
roomListEntries = new Dictionary();
}
void Start ()
{
Content = GameObject.Find("Content").GetComponent();
RoomVector = new Vector2(370, this.transform.position.y);
}
private void ClearRoomListView()
{
foreach (GameObject entry in roomListEntries.Values)
{
Destroy(entry.gameObject);
}
roomListEntries.Clear();
}
private void UpdateRoomListView()
{
foreach (RoomInfo Item in cachedRoomList.Values)
{
RoomName = Item.Name;
PlayerAmount = Item.PlayerCount;
MaxPlayers = Item.MaxPlayers;
RoomVector.y -= 100;
GameObject RoomPrefab = Instantiate(roomPrefab, RoomVector, transform.rotation) as GameObject;
if (Item.PlayerCount == 0)
{
Destroy(RoomPrefab);
}
print(PhotonNetwork.CurrentLobby.Name);
RoomPrefab.transform.Find("RoomName").GetComponent().text = RoomName;
RoomPrefab.transform.Find("PlayerInt").GetComponent().text = PlayerAmount.ToString();
if (Item.MaxPlayers == 4)
{
GameObject.Find("IPlayerA").GetComponent().sprite = Four;
}
else if (Item.MaxPlayers == 2)
{
GameObject.Find("IPlayerA").GetComponent().sprite = Two;
}
else if (Item.MaxPlayers == 3)
{
GameObject.Find("IPlayerA").GetComponent().sprite = Three;
}
RoomPrefab.transform.SetParent(Content.transform);
}
}
public override void OnRoomListUpdate(List roomList)
{
ClearRoomListView();
UpdateCachedRoomList(roomList);
UpdateRoomListView();
print("Updated");
}
private void UpdateCachedRoomList(List roomList)
{
foreach (RoomInfo info in roomList)
{
// Remove room from cached room list if it got closed, became invisible or was marked as removed
if (!info.IsOpen || !info.IsVisible || info.RemovedFromList)
{
if (cachedRoomList.ContainsKey(info.Name))
{
cachedRoomList.Remove(info.Name);
}
continue;
}
// Update cached room info
if (cachedRoomList.ContainsKey(info.Name))
{
cachedRoomList[info.Name] = info;
}
else
{
cachedRoomList.Add(info.Name, info);
}
}
}
This script instantiates a button for every room in photon's server. If you click one button, you join that room. As I said, sometimes it work and sometimes it doesn't, sometimes it helped to comment the line PhotonNetwork.JoinLobby(), but that means that you wont see the rooms. Actually, even with or without the JoinLobby() line, it isn't working that well.
↧
↧
how to make master client destroy other's players objects?
Hello everyone, I am making a multiplayer game, and I made authoritive shooting with master client(regular clients cant create rooms, so they cant be master clients). When a shell hits a player, it damages the player. I am trying to Network - Destroy the hitplayer, if it has less HP than 0. But of course, it raises an error, because masterclient doesnt own the hitplayer. Any idea how to workaround this?
↧
network object still remains after the owner left the room
I am not 100% sure about this. I checked if there is the owner of the drifting object in the room, but I could not find it.
Of course, this happens not very often. These objects do not disappear until the room is closed.
Does this can happen or I am doing something wrong?
I wonder if I should do check regularly if there are some independent objects in the room? Please, I need some advice.
↧
How do I change Protocol to 1.6 in PUN 2.0
I recently changed to PUN 2.0 with self hosted server.
Here is the error message
Got a unexpected Disconnect in LoadBalancingClient
State: Disconnected.
Server: MasterServer
Trace: at Photon.Realtime.LoadBalancingClient.OnStatusChanged(StatusCode statusCode) in
C:\...\LoadBalancingClient.cs:line 2302
I searched the forum and found that changing Protocol to 1.6 would solve the problem, but the old PhotonNetwork.SwitchToProtocol(...) is no longer available. I wounder whats the new approach.
↧
↧
Pause serialization for specific player
Hi!
I'm sending a new scene via a custom command. But Photon doesn't seem to know about this so it sends object serializations of objects that aren't yet loaded in the lag time between sending and receiving the new scene command.
This results in a bit of warning on player connection.
What I'd basically need is to simply pause the view serialization sending for the specific player until he gets the new scene command.
Any easy way to do this?
↧
How to use photons SetSynchronizedValues()
Hi, I am trying to get a smooth movement of my player characters in multiplayer, and by reading this page http://doc.exitgames.com/en/pun/current/tutorials/rpg-movement I have decided that using Interpolare opstion SynchronizeValues with SetSynchronizedValues should be the right option as my player characters has quick direciton changes.
In my players movement script I run Move() in an Update() like this:
public void Move()
{
// fix decending speed issue (this makes you stop completly if you release the keys)
if (Input.GetKey(KeyCode.W) == false &&
Input.GetKey(KeyCode.S) == false &&
Input.GetKey(KeyCode.A) == false &&
Input.GetKey(KeyCode.D) == false)
{
runSpeed = 0;
}
else
{
runSpeed = gameObject.GetComponent().runSpeed;
}
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 velocity = new Vector3(moveH * runSpeed, moveV * runSpeed).normalized;
velocity *= runSpeed;
rigidbody2D.velocity = velocity;
gameObject.GetComponent().SetSynchronizedValues(velocity, 0f);
}
In the end of this function we can see that I am trying to synchronize the velocity value (it's a 2D game and I have no turn speed) but the players are still choppy on the other client. Am I doing this right?
↧
How to use photons SetSynchronizedValues()
Hi, I am trying to get a smooth movement of my player characters in multiplayer, and by reading this page https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/package-demos/rpg-movement I have decided that using Interpolare opstion SynchronizeValues with SetSynchronizedValues should be the right option as my player characters has quick direciton changes.
In my players movement script I run Move() in an Update() like this:
public void Move()
{
// fix decending speed issue (this makes you stop completly if you release the keys)
if (Input.GetKey(KeyCode.W) == false &&
Input.GetKey(KeyCode.S) == false &&
Input.GetKey(KeyCode.A) == false &&
Input.GetKey(KeyCode.D) == false)
{
runSpeed = 0;
}
else
{
runSpeed = gameObject.GetComponent().runSpeed;
}
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 velocity = new Vector3(moveH * runSpeed, moveV * runSpeed).normalized;
velocity *= runSpeed;
rigidbody2D.velocity = velocity;
gameObject.GetComponent().SetSynchronizedValues(velocity, 0f);
}
In the end of this function we can see that I am trying to synchronize the velocity value (it's a 2D game and I have no turn speed) but the players are still choppy on the other client. Am I doing this right?
↧
[Question] How to instantiate / spawn a camera as a remote object?
Hi, first let me explain what i'm trying to do and about my project. I'm using UFPS Multiplayer kit, and i want to instantiate a camera that follows the player.
This camera needs to be instantiated as a 'remote prefab' to be able to see the remote version of my player.
Right now the way i'm doing i can only see the 'Local' version of it:
_virtualCamera = PhotonNetwork.Instantiate("Virtual Cinematic Camera", new Vector3(0,0), Quaternion.identity, 0); //has photon view
My question is, how i can instantiate a camera as a new remote player ?
PS: Sorry my poor english
↧
↧
Setting CustomProperties for inactive players, overridden when player gets active. Photon PUN bug?
In our game we need to set custom properties for players that are inactive. Of course this works just fine. But when the inactive player gets active again after .ReconnectAndRejoin() he receives his old properties. So all the properties that were set when he was inactive get overridden.
This problem is also discussed here: (the fix suggested doesn't work) https://forum.photonengine.com/discussion/12284/setting-custom-player-properties-for-a-player-who-is-in-background-from-other-players
We are using: Photon PUN 2.4
↧
Can't connect to Photon Server.
I have been working on my project for few years now and today for some reason my game will not connect to Photons Server. It gave me this error:
TimeoutDisconnect while connecting to: 169.63.72.88:5055. Check if the server is available.
UnityEngine.Debug:LogWarning(Object)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2094)
ExitGames.Client.Photon.EnetPeer:SendOutgoingCommands()
ExitGames.Client.Photon.PhotonPeer:SendOutgoingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:177)
Checked the App ID code its fine, checked if Host Type is Photon Cloud, it is.
Is photon server down or something?
And no I'm not using the free version, Photon Pun+.
↧
Newtonsoft.Json.JsonConvert' is defined multiple times
im using Newtonsoft.Json in my scripts and when i import pun2 free version, i get this error. what should i do?
Assets/Photon/PhotonUnityNetworking/Code/Editor/AccountService.cs(203,49): error CS0433: The imported type `Newtonsoft.Json.JsonConvert' is defined multiple times
↧
PhotonView + DontDestoryOnLoad
I have a character which I instantiate with PhotonNetwork.Instantiate function. Then in the Awake() function of my character I call DontDestroyOnLoad(gameObject). However it gets destroyed anyway after scene changing. Is there a way I can save an object with PhotonView attached? Thank you!
↧
↧
Non master client can't see networked gameObjects
Hello,
I am making a 1 v 1 RTS game, my problem is that the non master client can only see objects instantiated by him only, not the ones instantiated by the master client, but on the other hand the master client can see the objects instantiated by him and the other player, the instantiated gameObjects are the same, they have a photonview synchronizing transform,rigidbiody and the animator,
the coroutine called to instantiate the units
IEnumerator Instantiator()
{
MyPlayerManager GM = cam.GetComponent();
GameObject BaseTower = GM.BaseTower;
TowerSelection TS = BaseTower.GetComponent();
int randUnit = Random.Range(0, units.Length);
GameObject Unit = units[randUnit];
Vector3 pos = new Vector3(BaseTower.transform.position.x, -0.06f, BaseTower.transform.position.z);
while (TS.NrOfUnits > 0)
{
PhotonNetwork.Instantiate(Unit.name, pos, Quaternion.identity,0);
TS.NrOfUnits--;
yield return new WaitForSeconds(0.08f);
}
}
and fot the units(instantiated gameobject) script, for the networking part I have this
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(_rb.position);
stream.SendNext(_rb.rotation);
stream.SendNext(_rb.velocity);
}
else
{
_networkPosition = (Vector3)stream.ReceiveNext();
_networkRotation = (Quaternion)stream.ReceiveNext();
_rb.velocity = (Vector3)stream.ReceiveNext();
float lag = Mathf.Abs((float)(PhotonNetwork.time - info.timestamp));
_networkPosition += (_rb.velocity * lag);
}
}
public void FixedUpdate()
{
if (!photonView.isMine)
{
_rb.position = Vector3.MoveTowards(_rb.position, _networkPosition, Time.fixedDeltaTime);
_rb.rotation = Quaternion.RotateTowards(_rb.rotation, _networkRotation, Time.fixedDeltaTime * 100.0f);
}
}
↧
Please help using photon in lan mode
Hi i am James Romam,
You see we are working on a vr multiplayer game, but we wan to to make a little demo for lan, and really we try everyting in order to made it work, we download the server sdk, start the load balancing, disable windows firewall and antivirus, set rules for the ports (UDP and TCP), we try a lot of crazy stuff, but nothings see to work.
On my last try we get this error
Connect() to '192.168.8.101' failed: System.Net.Sockets.SocketException: No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión.
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in :0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in :0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in :0
at ExitGames.Client.Photon.SocketTcp.DnsAndConnect () [0x0007b] in C:\Dev\photon-sdk-dotnet\PhotonDotnet\SocketTcp.cs:167
UnityEngine.Debug:LogError(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:1819)
ExitGames.Client.Photon.SocketTcp:DnsAndConnect() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/SocketTcp.cs:188)
can someone provideme some type of help?
Tanks for reading :smile:
↧
Disable RPC receiving on specific Photon View
Hi all.
In my game, player goes to uncontrolled fly in ragdoll like fashion, controlled by physics, after the death.
I am disabling photon view synchronization, because I don't need this body to be exactly the same on all clients in this sequence.
But sometimes this body hits different things on the scene and RPC on this body is being called, so it breaks the free float.
Is there any way to disable RPC receiving for this specific object?
Thank you.
↧
[PUN2] [Bug] OnRoomListUpdate gives only one room
Hello,
Here is what happens:
When {Player A} connects for the first time to photon, the RoomInfo list retrieved from OnRoomListUpdate is good. Then a random player {Player B} creates a new room, OnRoomListUpdate is being called on {Player A} side but it returns only one room, the one created by {Player B}
Is it a normal behavior?
Thanks
↧
↧
Players don't see spawned mobs
Hi, i'm begginer with Photon, i successfuly built the code to make the players join and play together in the same room.
But when i try to spawn something with
var herbivorousObject = PhotonNetwork.InstantiateSceneObject(SpawnablePrefabs.Find(go => go.CompareTag("herbivorous")).name, Vector3.zero, Quaternion.identity);
Or with PhotonNetwork.Instanciate() or even tried with custom stuff with RPC, either cases, the players can't see the spawned mobs.
Obviously the prefab has a PhotonView attached, also tried to add PhotonTransformView and set it as an observed component in the PhotonView ... Anyway nothing better
Anyone can help me ?
↧
Can't find other rooms in PUN 2
Hello,
I ran into this bug a couple days ago. I'm not really sure what's going on.
After I've connected, I create a room on Computer A. Then on Computer B, I connect, and take a look at the room list - no room appears. When I "Join Random Room" on Computer B, it just ends up creating its own room.
Neither client seems to be able to see any of the created rooms. I haven't made any chances to the network code recently, the bug just suddenly appeared while I was testing. It also seems to appear in the PUN demo examples.
Any idea what's going on?
↧
Serialising simple custom objects over RPC (I know, I know :-)
Hi,
I've seen this question asked a LOT and just wondered if there was a definitive answer or if anything has been implemented in Photon over the years? Photon seems like the PERFECT nexus to implement something for everyone. I have use Custom Type registration provided by Photon (https://doc.photonengine.com/en-us/realtime/current/reference/serialization-in-photon) but it's a manual effort and not as readable/intuitive as it could be IMHO. Limited to 255 types too I think (huge, but still an arbitrary limit).
It seems very common (and sensible) that you would want to take a simple custom class, comprising only serialisable fields like int, Vector3, List, etc. and serialise/deserialise that over an RPC call or stored in room properties, etc. It would increase dev options and make syncing pratcially a "no brainer".
There are a few "serialisation assets" (e.g. https://assetstore.unity.com/packages/tools/input-management/easy-save-the-complete-save-load-asset-768, ) but these seem to focus on saving gameobjects, textures, scene state, etc. to local disk storage. They have the capability of assessing and serialising almost any object but the use case never seems to include taking the serialised data and just putting it in a variable e.g. byte[] that we could then put in an RPC call or Room Property. Has anyone used these assets in this way? Just want to check if it's a good idea because I'd buy it today!
Anyone using protbuf with Photon https://github.com/mgravell/protobuf-net?
Interested to hear any ideas!!
Thanks!
↧